Useful Linux Commands

Sep 28, 2017 Linux Ubuntu
Useful Linux Commands

In this tutorial we will go though some useful linux commands that can be very powerful for linux administrator or developers.

Top Command

One of the most basic command to monitor processes on Linux is the top command. The usage of this command is shown below:

$ top -v // checks the version of top command
$ top    // displays top process using most cpu

ls Command

This command is used to list directories and files on linux system. Command can be used as following:

$ ls       // lists the current directory
$ ls -l    // shows file or directory, size, modified date and time
$ ls -la   // lists all files including hidden file
$ ls -lh   // list Files with Human Readable Format
$ ls -R    // list all files in current directories and sub directories
$ ls -lS   // sort files by size

head/tail/cat Command

Head is used to display the first parts of a file, it outputs the first 10 lines by default while tail is opposite of head command displays last 10 lines of the given file.

# list all contents of the file
$ cat sample.txt

# list first 10 lines of the given file
$ head /var/log/apache2/error.log   

# display last 10 lines of the given file
$ tail /var/log/apache2/error.log   

# show first 100 lines of the file
$ head -100 /var/log/apache2/error.log   

# show last 100 lines of the file
$ tail -100 /var/log/apache2/error.log   

chmod Command

This command is used to assign file permissions on linux system.

# block (remove read, write and execute privileges) file or directory
# from other users and groups from accessing it 
$ chmod 700
$ chmod go-rwx

# assign read/write/execute permission
# chmod 777
# chmod -R 777 directory

Other Commands

# rename or move a file
$ mv existing.file new.file

# command below renames all .pdf files to .doc
$ rename -v 's/\.pdf$/\.doc/' *.pdf

# check apache logs
# tail -f /var/log/apache2/error.log

# send an email command line
$ echo "Message Body Here" | mail -s "Subject Here" [email protected] -A

# find php.ini file
$ php -i | grep "Loaded Configuration File"

# find mysql config file
$ mysql --help | grep -A1 'Default options'

# empty file contents
# cat /dev/null > access.log

# find process by name
$ ps aux | grep "mysql"
Rate This Article

Top linux commands that comes handy for linux administrator. This commands can be very powerful.


About Author

Sandip Patel
Sandip Patel

Sandip is passionate about bringing positivity to our communities through story-telling and sharing of real tech blogs.