List of useful linux commands

If you are a developer working a lot on linux or ubutu operating system. You may want to know some of the useful linux commands that can be very useful while performing day to day task.

Linux top command

Top command displays processor activity of our linux server and show realtime task managed by kernal.

# checks the version 
# of top command
$ top -v 

# displays top process 
# using most cpu
$ top  

# display specific user related tasks
$ top -u username

Linux ls command

ls command is very popular command used in linux. It is used to list directory files and folders.

$ 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
$ ls -r    // list the files and directories in revers order
$ ls -ltr  // show recently modified files and folders

Linux head command

Linux head command is used to display first part of the file. It takes the top 10 lines from the beginning.

# 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   

Linux chmod command

Linux chmod command is used to assign file permissions:

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

# assign read/write/execute permission
# to current file or dir only
$ chmod 777 secret.info

# assign read/write/execute permissions
# for current directory and its sub dirs
$ chmod -R 777 directory

How to move/rename a file in linux?

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

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

How to send command line email in linux?

# send an email command line
$ echo "Message Body Here" \
| mail -s "Subject Here" user@example.com -A attachment.zip

How to find php.ini file location ?

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

How to check logs file in linux?

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

How to find mysql config file in linux?

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

How to find running process by name in linux?

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

How to empty file contents in linux?

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

News and Updates

Subscribe to our newsletter and receive the latest news from TheThemeio.


Related Tags


Related Articles