Some Important Commands Used In Linux/Unix


Command-line interface(CLI) is a way that allows users to interact with computer programs through commands. A user issues commands to a program which gets interpreted by a command-line interpreter. Most operating system implements CLI in the form of shells that are used for interactive access of the various services or functions of the operating system. CLI has its own benefits over a graphical user interface(GUI). The command-line interface is more efficient than a GUI. A program can be accessed through CLI, which is not accessible on GUI. So in this article we are going to discuss some important commands that are used in Linux/Unix terminal frequently.


File commands –

COMMANDS DESCRIPTION
ls List files and directories under the current working directory
pwd Show the path of the current working directory
mkdir dir(s) Make a directory with name dir
cd dir Change directory to dir
cd Change the current directory to home directory
rm -r dir(s) Remove or delete the directory dir
rm -rf dir(s) Delete the directory dir forcefully
touch file(s) Create a file
rm file(s) Delete the file
rm -f file(s) Delete the file forcefully
cat >file Place the standard input into the file
cp file1 file2 Copy the content of file1 to file2
cp -r dir1 dir2 Copy the directory dir1 to dir2
mv file_or_directory dir Move a file or directory to directory dir

System info commands –

COMMANDS DESCRIPTION
date Show the current date and time
cal Show the month’s calendar
uptime Show the current uptime(total time of the current session since you log in)
w Display who is online
whoami Display who are you logged in as
uname -a Display the kernel information
finger user_name Display about the user
man command Display the manual for the given command
df Show the disk usage and other related information
du Show directory space usage
free Show the physical memory and swap usage
cat /proc/cpuinfo Display Cpu information
cat /proc/meminfo Display Memory information

File/directory searching commands –

COMMANDS DESCRIPTION
grep pattern Search for patterns in a file
grep -r pattern dir Search recursively for a pattern in dir
command | grep pattern Search pattern in the output of a command
locate file Display the path of the file with other file having a similar name
find .-name filename Searches in the current directory and below it for files and directories with the names starting with filename
pgrep pattern Searches for all the named processes, that matches with the pattern and by default, it returns their process ID

Commands used in process management –

COMMANDS DESCRIPTION
ps Display the current working process
top Display the all running process with resource usage
kill pid Kill the process with given process ID
killall -9 name If more than one process runs with that name, all of them will be killed
pkill pattern Kill the multiple process matches with pattern
bg Resume a stopped job in the background
fg Resume a stopped job in the foreground

Detailed use of process management commands with examples are given in a separate article. You should read process management in Linux/Unix.


File permission commands –

chmod octal file -Change the permission of file to octal, which can be found separately for user, group, world by adding, 4-read(r), 2-write(w), 1-execute(x). For detailed use of file permission commands, you should read this article file ownership and permissions in Linux/Unix.


Network commands –

COMMANDS DESCRIPTION
ping host Ping the given host and output the result
whois domain Display the information about domain and its owner
dig domain Display DNS information for a domain
dig -x host Reverse lookup host
wget file Download file
wget -c file Continue a stopped download

Compression commands –

COMMANDS DESCRIPTION
tar cf file.tar file(s) Create tar named file.tar containing file
tar xf file.tar Extract the files from file.tar
tar czf file.tar.gz file(s) Create a tar with gzip compression
tar xzf file.tar.gz Extract a tar using Gzip
tar cjf file.tar.bz2 file(s) Create tar with Bzip2 compression
tar xjf file.tar.bz2 Extract a tar using Bzip2
gzip file Compress file and rename it to file.gz
gzip -d file.gz Decompress file.gz back to file

 


Shortcuts used in Linux/Unix terminal –

COMMANDS DESCRIPTION
ctrl+c Halts the current command
ctrl+z Suspend the current command and can be resumed using fg or bg
ctrl+d Logout the current session
ctrl+w Erases one word in the line
ctrl+u Erases the whole line
ctrl+r Type to bring up whole command or reverse search
!! Repeat the last command
exit Logout the current session

 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.