Here I will list some parameters which people use very ofen, I will attach the output of the command with one parameters as well.
1. Create a new user:useradd
Parameter:
- Create new user:
useradd name
- Create new user with a default home directory:
useradd -m name
- Create new user with specified shell:
useradd -s /path/to/shell name
- Create new user with supplementary groups (mind the lack of whitespace):
useradd -G group1,group2 name
Sample:
1 [root@TestingMachine Desktop]# useradd -s /bin/shell test 2 [root@TestingMachine Desktop]#
2. Modifies a user account: usermod
Parameter:
- Change a user's name:
usermod -l newname user
- Add user to supplementary groups (mind the whitespace):
usermod -a -G group1,group2 user
- Create a new home directory for a user and move their files to it:
usermod -m -d /path/to/home user
Sample:
1 [root@TestingMachine Desktop]# usermod -p 123456 test 2 [root@TestingMachine Desktop]#
3. Remove a user:userdel
Pamater:
- Remove a user and their home directory:
userdel -r name
Sample:
1 [root@TestingMachine Desktop]# userdel -r test 2 [root@TestingMachine Desktop]#
4. passwd: Passwd is a tool used to change a user's password.
Parameter:
- Change the password of the current user:
passwd new password
- Change the password of the specified user:
passwd username new password
- Get the current statuts of the user:
passwd -S
- Make the password of the account blank (it will set the named account passwordless):
passwd -d
Sample:
1 [root@TestingMachine Desktop]# passwd test 2 Changing password for user test. 3 New password: 4 BAD PASSWORD: it is too simplistic/systematic 5 BAD PASSWORD: is too simple 6 Retype new password: 7 passwd: all authentication tokens updated successfully. 8 [root@TestingMachine Desktop]#
5. ls:List directory contents.
Parameter:
- List files one per line:
ls -1
- List all files, including hidden files:
ls -a
- Long format list (permissions, ownership, size and modification date) of all files:
ls -la
- Long format list with size displayed using human readable units (KB, MB, GB):
ls -lh
- Long format list sorted by size (descending):
ls -lS
- Long format list of all files, sorted by modification date (oldest first):
ls -ltr
Sample:
1 [root@TestingMachine Desktop]# ls -lS 2 total 3804180 3 -rw-r--r--. 1 root root 3895459840 May 10 12:16 CentOS-6.7-x86_64-bin-DVD1.iso 4 -rwxr-xr-x. 1 root root 6333 May 10 14:12 gnome-terminal.desktop 5 drwxr-xr-x. 3 root root 4096 May 14 13:39 Python_file 6 -rw-r--r--. 1 root root 979 May 11 14:01 linux_command 7 -rw-r--r--. 1 root root 0 May 14 14:24 test
6. cp:Copy files.
Parameter:
- Copy files in arbitrary locations:
cp /path/to/original /path/to/copy
- Copy a file to a parent directory:
cp /path/to/original ../path/to/copy
- Copy directories recursive using the option -r:
cp -r /path/to/original /path/to/copy
- Show files as they are copied:
cp -vr /path/to/original /path/to/copy
- Make a copy of a file, adding an extension:
cp file.html{,.backup}
- Make a copy of a file, changing the extension:
cp file.{html,backup}
Sample:
1 [root@TestingMachine Desktop]# ls -al test* 2 -rw-r--r--. 1 root root 0 May 14 14:24 test.txt 3 [root@TestingMachine Desktop]# cp test.{txt,html} 4 [root@TestingMachine Desktop]# ls -al test* 5 -rw-r--r--. 1 root root 0 May 14 15:23 test.html 6 -rw-r--r--. 1 root root 0 May 14 14:24 test.txt
7. mv:Move or rename files and directories.
Parameter:
- Move files in arbitrary locations:
mv source target
- Do not prompt for confirmation before overwriting existing files:
mv -f source target
- Do not prompt for confirmation before overwriting existing files but write to standard error before overriding:
mv -fi source target
- Move files in verbose mode, showing files after they are moved:
mv -v source target
Sample:
1 [root@TestingMachine Desktop]# mv -v test.html /home/test 2 `test.html' -> `/home/test/test.html'
8. rm:Remove files or directories.
Sample:
- Remove files from arbitrary locations:
rm /path/to/file /otherpath/to/file2
- Remove recursively a directory and all its subdirectories:
rm -r /path/to/folder
- Remove directory without prompt:
rm -rf /path/to/folder
- Prompt before every removal:
rm -i *
Sample:
[root@TestingMachine test]# ls -al total 12 drwxr-xr-x. 3 root root 4096 May 14 15:30 . drwxr-xr-x. 4 root root 4096 May 14 15:30 .. drwxr-xr-x. 2 root root 4096 May 14 15:30 test [root@TestingMachine test]# rm -rf test [root@TestingMachine test]# ls -al total 8 drwxr-xr-x. 2 root root 4096 May 14 15:30 . drwxr-xr-x. 4 root root 4096 May 14 15:30 ..
9. mkdir: Creates a directory.
Parameter:
- Create a directory in current folder or given path:
mkdir directory
- Create directories recursively (useful for creating nested dirs):
mkdir -p path
Sample:
1 [root@TestingMachine Desktop]# mkdir -p test/test1/test2/test3 2 [root@TestingMachine Desktop]# ls -al test/test1/test2/test3 3 total 8 4 drwxr-xr-x. 2 root root 4096 May 14 15:32 . 5 drwxr-xr-x. 3 root root 4096 May 14 15:32 ..
10. rmdir:Removes a directory.
Parameter:
- Remove directory, provided it is empty. Use `rm` to remove not empty directories:
rmdir directory
- Remove directories recursively (useful for nested dirs):
rmdir -p path
Sample:
1 [root@TestingMachine Desktop]# ls -al test/test1/test2/test3 2 total 8 3 drwxr-xr-x. 2 root root 4096 May 14 15:32 . 4 drwxr-xr-x. 3 root root 4096 May 14 15:32 .. 5 [root@TestingMachine Desktop]# rmdir -p test/test1/test2/test3 6 [root@TestingMachine Desktop]# ls -al 7 total 3804188 8 drwxr-xr-x. 3 root root 4096 May 14 15:35 . 9 dr-xr-x---. 27 root root 4096 May 14 14:10 .. 10 -rw-r--r--. 1 root root 3895459840 May 10 12:16 CentOS-6.7-x86_64-bin-DVD1.iso 11 -rwxr-xr-x. 1 root root 6333 May 10 14:12 gnome-terminal.desktop 12 -rw-r--r--. 1 root root 979 May 11 14:01 linux_command 13 drwxr-xr-x. 3 root root 4096 May 14 13:39 Python_file 14 -rw-r--r--. 1 root root 0 May 14 14:24 test.txt
11. cd:Change the current working directory.
Parameter:
- Go to the given directory:
cd /path/to/directory
- Go to home directory of current user:
cd
- Go up to the parent of the current directory:
cd ..
- Go to the previously chosen directory:
cd -
Sample:
1 [root@TestingMachine Desktop]# cd 2 [root@TestingMachine ~]#
12. chmod:Change the access permissions of a file or directory.
Parameter:
- Give the (u)ser who owns a file the right to e(x)ecute it:
chmod u+x file
- Give the user rights to (r)ead and (w)rite to a file/directory:
chmod u+rw file
- Remove executable rights from the (g)roup:
chmod g-x file
- Give (a)ll users rights to read and execute:
chmod a+rx file
- Give (o)thers (not in the file owner's group) the same rights as the group:
chmod o=g file
Sample:
[root@TestingMachine Desktop]# ls -al test.txt -rw-r--r--. 1 root root 0 May 14 14:24 test.txt [root@TestingMachine Desktop]# chmod a+rx test.txt [root@TestingMachine Desktop]# ls -al test.txt -rwxr-xr-x. 1 root root 0 May 14 14:24 test.txt
13. chown:Change user and group ownership of files and folders.
Parameter:
- Change the owner user of a file/folder:
chown user path/to/file
- Change the owner user and group of a file/folder:
chown user:group path/to/file
- Recursively change the owner of a folder and its contents:
chown -R user path/to/folder
- Change the owner of a symbolic link:
chown -h user path/to/symlink
- Change the owner of a file/folder to match a reference file:
chown --reference=path/to/reference_file path/to/file
Sample:
[root@TestingMachine Desktop]# ls -al test.txt -rwxr-xr-x. 1 root root 0 May 14 14:24 test.txt [root@TestingMachine Desktop]# chown -R test test.txt [root@TestingMachine Desktop]# ls -al test.txt -rwxr-xr-x. 1 test root 0 May 14 14:24 test.txt
14. find:Find files under the given directory tree, recursively.
Parameter:
- Find files by extension:
find root_path -name '*.py'
- Find files matching path pattern:
find root_path -path '**/lib/**/*.py'
- Run a command for each file, use {} within the command to access the filename:
find root_path -name '*.py' -exec wc -l {} ;
- Find files modified since a certain time:
find root_path -name '*.py' -mtime -1d
- Find files using case insensitive name matching, of a certain size:
find root_path -size +500k -size -10MB -iname '*.TaR.gZ'
- Delete files by name, older than a certain number of days:
find root_path -name '*.py' -mtime -180d -delete
- Find empty files or directories:
find root_path -empty
- Find files matching more than one search criteria:
find root_path -name '*.py' -or -name '*.r'
Sample:
1 [root@TestingMachine Desktop]# find /root -name '*.txt' -mtime -180 | more 2 /root/Desktop/test.txt 3 /root/Downloads/pycharm-community-2016.1.2/plugins/svn4idea/lib/licenses/LICENSE 4 -JAVAHL.txt 5 /root/Downloads/pycharm-community-2016.1.2/plugins/svn4idea/lib/licenses/SQLJET- 6 README.txt
15. date:Set or display the system date.
Parameter:
- Display the date using the default locale:
date +"%c"
- Display the date in UTC and ISO 8601 format:
date -u +"%Y-%m-%dT%H:%M:%SZ"
Sample:
1 [root@TestingMachine Desktop]# date -u +"%Y-%m-%dT%H:%M:%SZ" 2 2016-05-14T07:54:45Z 3 [root@TestingMachine Desktop]#
16. reboot: Reboot the system.
Parameter:
- Reboot immediately:
reboot
- Reboot immediately without gracefully shutdown:
reboot -f
Sample:
1 [root@TestingMachine Desktop]# reboot -r
17. shutdown:Shutdown and reboot the system.
Parameter:
- Power off (halt) immediately:
shutdown -h now
- Reboot immediately:
shutdown -r now
- Reboot in 5 minutes:
shutdown -r +5 &
- Shutdown at 1:00 pm (Uses 24h clock):
shutdown -h 13:00
- Cancel a pending shutdown/reboot operation:
shutdown -c
Sample:
1 [root@TestingMachine Desktop]# shutdown -h now
18. route:Use route cmd to set the route table .
Paramter:
- Display the information of route table:
route -n
- Add route rule:
sudo route add -net ip_address netmask netmask_address gw gw_address
- Delete route rule:
sudo route del -net ip_address netmask netmask_address dev gw_address
Sample:
1 [root@TestingMachine Desktop]# route -n 2 Kernel IP routing table 3 Destination Gateway Genmask Flags Metric Ref Use Iface 4 10.0.8.0 0.0.0.0 255.255.252.0 U 2 0 0 wlan0 5 0.0.0.0 10.0.8.1 0.0.0.0 UG 0 0 0 wlan0
19. Ifconfig: Interface Configurator, used to configure network interfaces.
Parameter:
- View network settings of an ethernet adapter:
ifconfig eth0
- Display details of all interfaces, including disabled interfaces:
ifconfig -a
- Disable eth0 interface:
ifconfig eth0 down
- Enable eth0 interface:
ifconfig eth0 up
- Assign IP address to eth0 interface:
ifconfig eth0 ip_address
Sample:
[root@TestingMachine Desktop]# ifconfig -a em1 Link encap:Ethernet HWaddr F8:CA:B8:17:EA:1B UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) Interrupt:20 Memory:f7100000-f7120000
20. hostname:Show or set the system's host name.
Parameter:
- Show current host name:
hostname
- Show the network address of the host name:
hostname -i
- Show all network addresses of the host:
hostname -I
- Show the FQDN (Fully Qualified Domain Name):
hostname --fqdn
- Set current host name:
hostname new_hostname
Sample:
[root@TestingMachine Desktop]# hostname -I 10.0.9.234
21. last:View the last logged in users.
Parameter:
- View last logins, their duration and other information as read from /var/log/wtmp:
last
- Specify how many of the last logins to show:
last -n login_count
- View full login times and dates:
last -F
- View the last login by a specific user:
last user_name
- View the last reboot (last login of the pseudo user reboot):
last reboot
- View the last shutdown (last login of the pseudo user shutdown):
last shutdown
Sample:
[root@TestingMachine Desktop]# last shutdown wtmp begins Tue May 10 14:06:38 2016
22. w:Show who is logged on and what they are doing. Print user login, TTY, remote host, login time, idle time, current process.
Parameter:
- Show logged-in users info:
w
- Show logged-in users info without a header:
w -h
Sample:
1 [root@TestingMachine Desktop]# w -h 2 root tty1 :0 14:09 2:05m 2:38 2:38 /usr/bin/Xorg : 3 root pts/0 :0.0 14:11 1:07 0.07s 0.07s bash 4 root pts/1 :0.0 14:16 0.00s 0.19s 0.00s w -h 5 [root@TestingMachine Desktop]#
23. watch:Execute a program periodically, showing output fullscreen.
Parameter:
- Repeatedly run a command and show the result:
watch command
- Re-run a command every 60 seconds:
watch -n 60 command
- Monitor the contents of a directory, highlighting differences as they appear:
watch -d ls -l
Sample:
1 [root@TestingMachine Desktop]# watch -d ls -l 2 [root@TestingMachine Desktop]#
24. pgrep:Find or signal process by name.
Parameter:
- Return PIDs of any running processes with a matching command string:
pgrep process_name
- Search full command line with parameters instead of just the process name:
pgrep -f "process_name parameter"
- Search for process run by a specific user:
pgrep -u root process_name
Sample:
1 [root@TestingMachine Desktop]# pgrep -u root ssh 2 3020
25. nohup:Allows for a process to live when the terminal gets killed.
Parameter:
- Run process that can live beyond the terminal:
nohup command options
Sample:
1 [root@TestingMachine Desktop]# nohup ls -al > myout 2>&1 2 [root@TestingMachine Desktop]# ls -al myout 3 -rw-r--r--. 1 root root 528 May 14 16:22 myout
26. ipcs:Display information about ressources used in IPC (Inter-process Communication).
Parameter:
- Specific information about the Message Queue which has the id 32768:
ipcs -qi 32768
- General information about all the IPC:
ipcs -a
Sample:
[root@TestingMachine Desktop]# ipcs -a ------ Shared Memory Segments -------- key shmid owner perms bytes nattch status 0x00000000 131072 root 600 393216 2 dest 0x00000000 163841 root 600 393216 2 dest 0x00000000 196610 root 600 393216 2 dest 0x00000000 229379 root 600 393216 2 dest 0x00000000 262148 root 600 393216 2 dest 0x00000000 294917 root 600 393216 2 dest 0x00000000 327686 root 600 393216 2 dest 0x00000000 360455 root 600 393216 2 dest 0x00000000 393224 root 600 393216 2 dest 0x00000000 425993 root 600 393216 2 dest 0x00000000 458762 root 600 393216 2 dest 0x00000000 491531 root 600 393216 2 dest 0x00000000 655373 root 600 393216 2 dest 0x00000000 688142 root 600 393216 2 dest ------ Semaphore Arrays -------- key semid owner perms nsems 0x00000000 0 root 600 1 0x00000000 32769 root 600 1 ------ Message Queues -------- key msqid owner perms used-bytes messages
27. ps:Information about running processes.
Parameter:
- List all running processes:
ps aux
- List all running processes including the full command string:
ps auxww
- Search for a process that matches a string:
ps aux | grep string
Sample:
1 [root@TestingMachine Desktop]# ps aux|grep update 2 root 3548 0.0 0.0 281712 8492 ? S 14:10 0:00 gpk-update-icon 3 root 5421 0.0 0.0 103312 864 pts/1 S+ 16:26 0:00 grep update
28. crontab:Schedule cron jobs to run on a time interval for the current user.
Parameter:
- Edit the crontab file for the current user:
crontab -e
- View a list of existing cron jobs for current user:
crontab -l
- Remove all cron jobs for the current user:
crontab -r
Sample:
1 [root@TestingMachine Desktop]# crontab -l 2 no crontab for root
29. ping:Send ICMP ECHO_REQUEST packets to network hosts.
Parameter:
- Ping host:
ping host
- Ping a host only a specific number of times:
ping -c count host
- Ping host, specifying the interval in seconds between requests (default is 1 second):
ping -i seconds host
- Ping host without trying to lookup symbolic names for addresses:
ping -n host
Sample:
1 [root@TestingMachine Desktop]# ping -c 4 10.0.9.234 2 PING 10.0.9.234 (10.0.9.234) 56(84) bytes of data. 3 64 bytes from 10.0.9.234: icmp_seq=1 ttl=64 time=0.063 ms 4 64 bytes from 10.0.9.234: icmp_seq=2 ttl=64 time=0.050 ms 5 64 bytes from 10.0.9.234: icmp_seq=3 ttl=64 time=0.050 ms 6 64 bytes from 10.0.9.234: icmp_seq=4 ttl=64 time=0.021 ms 7 8 --- 10.0.9.234 ping statistics --- 9 4 packets transmitted, 4 received, 0% packet loss, time 2999ms 10 rtt min/avg/max/mdev = 0.021/0.046/0.063/0.015 ms
30. traceroute:Print the route packets trace to network host.
Parameter:
- Traceroute to a host:
traceroute host
- Disable IP address and host name mapping:
traceroute -n host
- Specify wait time for response:
traceroute -w 0.5 host
- Specify number of queries per hop:
traceroute -q 5 host
Sample:
[root@TestingMachine Desktop]# traceroute www.baidu.com traceroute to www.baidu.com (61.135.169.121), 30 hops max, 60 byte packets 1 10.0.8.1 (10.0.8.1) 7.095 ms 7.105 ms 7.105 ms 2 172.19.141.177 (172.19.141.177) 10.667 ms 10.673 ms 10.677 ms 3 172.16.0.81 (172.16.0.81) 10.617 ms 11.419 ms 11.437 ms 4 * * * 5 61.148.50.113 (61.148.50.113) 35.461 ms 35.490 ms 35.491 ms 6 61.148.6.193 (61.148.6.193) 19.384 ms bt-229-117.bta.net.cn (202.106.229.117) 6.069 ms 61.148.154.249 (61.148.154.249) 6.032 ms 7 61.148.156.177 (61.148.156.177) 10.794 ms 8.855 ms 8.797 ms 8 123.126.6.118 (123.126.6.118) 8.710 ms 12.046 ms 24.462 ms 9 61.49.168.86 (61.49.168.86) 55.927 ms 61.49.168.82 (61.49.168.82) 35.308 ms 61.49.168.86 (61.49.168.86) 55.922 ms
31. netstat:Displays various networks related information such as open connections, open socket ports etc.
Parameter:
- List all ports:
netstat -a
- List all listening ports:
netstat -l
- List listening TCP ports:
netstat -t
- Display PID and program names:
netstat -p
- List information continuously:
netstat -c
- List routes and do not resolve IP to hostname:
netstat -rn
- List listening TCP and UDP ports (+ user and process if you're root):
netstat -lepunt
Sample:
[root@TestingMachine Desktop]# netstat -t Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 1 0 10.0.9.234:50976 a23-201-102-34.deploy.:http CLOSE_WAIT
32. mount:Provides access to an entire filesystem in one directory.
Parameter:
- Show all mounted filesystems:
mount
- Mount a device:
mount -t filesystem_type path_to_device_file directory_to_mount_to
- Mount a CD-ROM device (with the filetype ISO9660) to /cdrom (readonly):
mount -t iso9660 -o ro /dev/cdrom /cdrom
- Mount all the filesystem defined in /etc/fstab:
mount -a
- Mount a specific filesystem described in /etc/fstab (e.g. "/dev/sda1 /my_drive ext2 defaults 0 2"):
mount /my_drive
Sample:
[root@TestingMachine Desktop]# mount CentOS-6.7-x86_64-bin-DVD1.iso /mnt/iso -o loop [root@TestingMachine Desktop]#
33. mke2fs:Creates a Linux filesystem inside a partition.
Parameter:
- Create an ext2 filesystem in partition 1 of device b (`sdb1`):
mkfs.ext2 /dev/sdb1
- Create an ext3 filesystem in partition 1 of device b (`sdb1`):
mkfs.ext3 /dev/sdb1
Sample:
[root@TestingMachine Desktop]# mke2fs -q /dev/sda1 /dev/sda1 is mounted; will not make a filesystem here!
34. which:Locate the a program in the user's path.
Parameter:
- Search the PATH environment variable and display the location of any matching executables:
which executable
- If there are multiple executables which match, display all:
which -a executable
Sample:
[root@TestingMachine Desktop]# which python /usr/local/bin/python
35. who:Display who is logged in and related data (processes, boot time).
Parameter:
- Display the username, line, and time of all currently logged-in sessions:
who
- Display information only for the current terminal session:
who am i
- Display all available information:
who -a
- Display all available information with table headers:
who -a -H
Sample:
[root@TestingMachine Desktop]# who -a -H NAME LINE TIME IDLE PID COMMENT EXIT system boot 2016-05-14 14:09 run-level 5 2016-05-14 14:09 LOGIN tty3 2016-05-14 14:09 3226 id=3 LOGIN tty2 2016-05-14 14:09 3224 id=2 LOGIN tty4 2016-05-14 14:09 3228 id=4 LOGIN tty5 2016-05-14 14:09 3230 id=5 LOGIN tty6 2016-05-14 14:09 3232 id=6 root + tty1 2016-05-14 14:09 old 3396 (:0) root + pts/0 2016-05-14 14:11 . 4239 (:0.0) root + pts/1 2016-05-14 14:16 . 4239 (:0.0)
36. touch:Change a file access and modification times (atime, mtime).
Parameter:
- Create a new empty file(s) or change the times for existing file(s) to current time:
touch filename
- Set the times on a file to a specific date and time:
touch -t YYYYMMDDHHMM.SS filename
- Use the times from a file to set the times on a second file:
touch -r filename filename2
Sample:
[root@TestingMachine Desktop]# touch -r test.txt test [root@TestingMachine Desktop]# ls -al tes* -rw-r--r--. 1 root root 0 May 14 14:24 test -rwxr-xr-x. 1 test root 0 May 14 14:24 test.txt
37. head:Output the first part of files.
Parameter:
- Output the first few lines of a file:
head -n count_of_lines filename
- Output the first few bytes of a file:
head -c size_in_bytes filename
Sample:
[root@TestingMachine Desktop]# head -n 5 myout nohup: ignoring input total 3804192 drwxr-xr-x. 3 root root 4096 May 14 16:22 . dr-xr-x---. 27 root root 4096 May 14 14:10 .. -rw-r--r--. 1 root root 3895459840 May 10 12:16 CentOS-6.7-x86_64-bin-DVD1.iso
38. tail:Display the last part of a file.
Parameter:
- Show last 'num' lines in file:
tail -n num file
- Show all file since line 'num':
tail -n +num file
- Show last 'num' bytes in file:
tail -c num file
- Keep reading file until ctrl-c:
tail -f file
Sample:
[root@TestingMachine Desktop]# tail -n 5 myout -rwxr-xr-x. 1 root root 6333 May 10 14:12 gnome-terminal.desktop -rw-r--r--. 1 root root 979 May 11 14:01 linux_command -rw-r--r--. 1 root root 22 May 14 16:22 myout drwxr-xr-x. 3 root root 4096 May 14 13:39 Python_file -rwxr-xr-x. 1 test root 0 May 14 14:24 test.txt
39. diff: Compare files and directories.
Parameter:
- Compare files:
diff file1 file2
- Compare files, ignoring white spaces:
diff -w file1 file2
- Compare files, showing differences side by side:
diff -y file1 file2
- Compare directories recursively:
diff -r directory1 directory2
- Compare directories, only showing the names of files that differ:
diff -rq directory1 directory2
Sample:
1 [root@TestingMachine Desktop]# diff -w myout myout1 2 2c2 3 < total 4804192 4 --- 5 > total 3804192 6 4a5 7 > -rw-r--r--. 1 root root 3895459840 May 10 12:16 CentOS-6.7-x86_64-bin-DVD1.iso
40. sort:Sort lines of text files.
Parameter:
- Sort a file in ascending order:
sort filename
- Sort a file in descending order:
sort -r filename
- Sort a file using numeric rather than alphabetic order:
sort -n filename
- Sort the passwd file by the 3rd field, numerically:
sort -t: -k 3n /etc/passwd
- Sort a file preserving only unique lines:
sort -u filename
Sample:
[root@TestingMachine Desktop]# sort -t ":" -k 3n /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync
41. wc:Count words, bytes, or lines.
Parameter:
- Count lines in file:
wc -l file
- Count words in file:
wc -w file
- Count characters (bytes) in file:
wc -c file
- Count characters in file (taking multi-byte character sets into account):
wc -m file
Sample:
[root@TestingMachine Desktop]# wc -l /etc/passwd 33 /etc/passwd
42. locate:Find filenames quickly.
Parameter:
- Look for pattern in the database. Note: the database is recomputed periodically (usually weekly or daily):
locate pattern
- Recompute the database. You need to do it if you want to find recently added files:
sudo updatedb
Sample:
[root@TestingMachine Desktop]# locate test.txt /root/Downloads/Python-2.7.11/Lib/test/test_doctest.txt /root/Downloads/Python-3.5.1/Lib/test/test_doctest.txt /usr/local/lib/python2.7/test/test_doctest.txt /usr/local/lib/python3.5/test/test_doctest.txt
43. gzip:Compress/uncompress files with gzip compression (LZ77).
Parameter:
- Compress a file, replacing it with a gzipped compressed version:
gzip file.ext
- Decompress a file, replacing it with the original uncompressed version:
gzip -d file.ext.gz
- Compress a file specifying the output filename:
gzip -c file.ext > compressed-file.ext.gz
- Uncompress a gzipped file specifying the output filename:
gzip -c -d file.ext.gz > uncompressed-file.ext
- Specify the compression level. 1=Fastest (Worst), 9=Slowest (Best), Default level is 6:
gzip -9 -c file.ext > compressed-file.ext.gz
Sample:
[root@TestingMachine Desktop]# gzip -9 -c test.txt > compressed-file.ext.gz [root@TestingMachine Desktop]# ls CentOS-6.7-x86_64-bin-DVD1.iso linux_command Python_file compressed-file.ext.gz myout test
44. tar:Archiving utility. Optional compression with gzip / bzip.
Parameter:
- Create an archive from files:
tar cf target.tar file1 file2 file3
- Create a gzipped archive:
tar czf target.tar.gz file1 file2 file3
- Extract an archive in a target folder:
tar xf source.tar -C folder
- Extract a gzipped archive in the current directory:
tar xzf source.tar.gz
- Extract a bzipped archive in the current directory:
tar xjf source.tar.bz2
- Create a compressed archive, using archive suffix to determine the compression program:
tar caf target.tar.xz file1 file2 file3
- List the contents of a tar file:
tar tvf source.tar
Sample:
[root@TestingMachine Desktop]# tar cvf test.tar test.txt test.txt
45. df:Gives an overview of the file system disk space usage.
Parameter:
- Display all file systems and their disk usage:
df
- Display all file systems and their disk usage in human readable form:
df -h
Sample:
[root@TestingMachine Desktop]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 289G 8.6G 266G 4% / tmpfs 16G 228K 16G 1% /dev/shm /dev/sda1 7.6G 58M 7.2G 1% /boot /root/Desktop/CentOS-6.7-x86_64-bin-DVD1.iso 3.7G 3.7G 0 100% /mnt/iso
46 .top:Display dynamic real-time information about running processes.
Parameter:
- Start top:
top
- Start top ignoring any idle or zombie processes:
top -i
- Start top displaying only processes owned by given user:
top -u user-name
- Get help about interactive commands:
?
Sample:
[root@TestingMachine Desktop]# top -u test top - 17:44:53 up 3:35, 3 users, load average: 0.02, 0.02, 0.00 Tasks: 267 total, 1 running, 266 sleeping, 0 stopped, 0 zombie Cpu(s): 0.8%us, 0.3%sy, 0.0%ni, 99.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 32426484k total, 1784640k used, 30641844k free, 101120k buffers Swap: 8191996k total, 0k used, 8191996k free, 533040k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
47. kill:Sends a signal to a process. Mostly used for stopping processes.
Parameter:
- Kill the process:
kill process_id
- List signal names:
kill -l
Sample:
[root@TestingMachine Desktop]# kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR 31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8 43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2 63) SIGRTMAX-1 64) SIGRTMAX
48. telnet:Telnet is used to connect to a specified port of a host.
Parameter:
- Telnet to a certain port:
telnet ip_address port
- To exit a telnet session:
quit
- Default escape character:
CTRL + ]
- Specify an escape character (x is the escape character):
telnet -e x ip_address port
Sample:
[root@TestingMachine Desktop]# telnet 10.208.131.30 4189
49. man:Format and display manual pages.
Parameter:
- Display man page for a command:
man command
- Display path searched for manpages:
man --path
- Display location of a manpage rather than the manpage itself:
man -w command
- Do a keyword search for manpages containing a search string:
man -k keyword
Sample:
[root@TestingMachine Desktop]# man ssh
50. free:Display amount of free and used memory in the system.
Parameter:
- Display system memory:
free
- Display memory in Bytes/KB/MB/GB:
free -b/-k/-m/-g
- Display memory in human readable units:
free -h
- Continuous monitor memory (refresh every X seconds):
free -s X
Sample:
[root@TestingMachine Desktop]# free -h total used free shared buffers cached Mem: 30G 1.7G 29G 4.5M 99M 521M -/+ buffers/cache: 1.1G 29G Swap: 7.8G 0B 7.8G