Most frequently used Linux commands 3
View crontab entry for a specific user
# crontab -u john -l
Schedule a cron job every 10 minutes.
*/10 * * * * /home/ramesh/check-disk-space
Service command is used to run the system V init scripts. i.e Instead of calling the scripts located in the /etc/init.d/ directory with their full path, you can use the service command.
Check the status of a service:
# service ssh status
Check the status of all the services.
Restart a service.
# service ssh restart
ps command is used to display information about the processes that are running in the system.
While there are lot of arguments that could be passed to a ps command, following are some of the common ones.
To view current running processes.
$ ps -ef | more
To view current running processes in a tree structure. H option stands for process hierarchy.
$ ps -efH | more
This command is used to display the free, used, swap memory available in the system.
Typical free command output. The output is displayed in bytes.
If you want to quickly check how many GB of RAM your system has use the -g option. -b option displays in bytes, -k in kilo bytes, -m in mega bytes.
$ free -g
If you want to see a total memory ( including the swap), use the -t switch, which will display a total line as shown below.
$ free -t
top command displays the top processes in the system ( by default sorted by cpu usage ).
To displays only the processes that belong to a particular user use -u option. The following will show only the top processes that belongs to oracle user.
$ top -u oracle
Displays the file system disk space usage. By default df -k displays output in bytes.
$ df -k
df -h displays output in human readable form. i.e size will be displayed in GB’s.
$ df -h
Use -T option to display what type of file system.
$ df -T
Use kill command to terminate a process. First get the process id using ps -ef command, then use kill -9 to kill the running Linux process as shown below. You can also use killall, pkill, xkill to terminate a unix process.
$ ps -ef | grep vim
$ kill -9 7243
Get confirmation before removing the file.
$ rm -i filename.txt
It is very useful while giving shell metacharacters in the file name argument.
Print the filename and get confirmation before removing the file.
$ rm -i file*
Following example recursively removes all files and directories under the example directory. This also removes the example directory itself.
$ rm -r example
Copy file1 to file2 preserving the mode, ownership and timestamp.
$ cp -p file1 file2
Copy file1 to file2. if file2 exists prompt for confirmation before overwritting it.
$ cp -i file1 file2
Rename file1 to file2. if file2 exists prompt for confirmation before overwritting it.
$ mv -i file1 file2
Note: mv -f is just the opposite, which will overwrite file2 without prompting.
mv -v will print what is happening during file rename, which is useful while specifying shell metacharacters in the file name argument.
$ mv -v file1 file2
You can view multiple files at the same time. Following example prints the content of file1 followed by file2 to stdout.
$ cat file1 file2
While displaying the file, following cat -n command will prepend the line number to each line of the output.
$ cat -n /etc/logrotate.conf
Contents related to 'Most frequently used Linux commands 3'
Most frequently used Linux commands 1: Most frequently used linux commands, explanation of linux commands, examples of linux command usage.
Most frequently used Linux commands 2: Most frequently used linux commands 2, explanation of linux commands, examples of linux command usage.
Most frequently used Linux commands 4: Most frequently used linux commands 4, explanation of linux commands, examples of linux command usage.
Most frequently used Linux commands 5: Most frequently used linux commands 5, explanation of linux commands, examples of linux command usage.