Linux distributions support various GUIs (graphical user interfaces) but the old command line interface (bash) still proves to be easier and quicker in some situations. Bash and other Linux shells require you to type in commands to complete your tasks, and thus gets named the command line interface.
Commands are directives for the computer to carry out a task. You can use commands to shut down your computer, or show a list of files in the current directory or the contents of a text file, or to show a message on the screen. They’re easy and powerful at the same time.
If you are new to this and have always wanted to try it out, we’ve compiled a list of various basic Linux commands that you can learn and use for various tasks in several Linux distros. The list is not exhaustive but it should make for a good start for beginners or intermediate Linux users or administrators.
ls – List
ls
lists the contents (files and folders) of the current working directory. It’s the same as you opening a folder in file explorer to see its contents in GUI.
mkdir – Make Directory
mkdir <new-directory-name>
makes (or creates) a new directory. It’s the same as you using the context menu’s ‘new/create directory’ option to create a new folder (or directory) using file explorer in GUI.
pwd – Print Working Directory
pwd
prints the current working directory.
cd – Change Directory
cd <directory>
sets the given folder (or directory) as the current working directory for the current running session of the terminal (or bash). It’s the same as you opening a directory to do some operations using file explorer in GUI.
rmdir – Remove Directory
rmdir <directory-name>
removes (or deletes) the given directory.
rm – Remove
rm <file-name>
removes the given file or folder. You can use rm -r <directory-name>
to delete folders recursively.
cp – Copy
cp <source-file> <destination-file>
copies the file or folder from one location to another location. You can use its cp -r <source-folder> <destination-folder>
option to copy folders recursively.
mv – MoVe
mv <source> <destination>
moves a file or folder from one location to another location. It can also act to rename the file or folder if the file or folder is in the current working directory but the file or folder has a new name.
cat – concatenate and print files
cat <file>
concatenates and prints files on the standard output (i.e., the monitor or computer’s screen). It’s the same as you viewing contents of text files using text viewer or editor in GUI.
tail – print TAIL (from last)
>
tail <file-name>
prints the last 10 lines (by default) of the given file on the standard output (i.e., the computer’s screen or monitor). You can use tail -n N <file-name>
to dictate the last N number of lines to print on the screen.
less – print LESS
less <file-name>
prints the given file page by page (or window by window). It’s useful and efficient for viewing large files containing lots of textual data that won’t fit on the screen. You can press Ctrl+F to go forward and Ctrl+B to go backward by one page. It’s the same as you viewing the contents of a text file in a text viewer or editor and reading the file page by page in GUI.
grep
grep "<string>" <file-name>
searches for a given string in a given file. You can use grep -i "<string>" <file-name>
to make a case-insensitive search and grep -r "<string>"
<file-name>
to search for the given string in all files recursively in the current working directory.
Find
This command searches for files matching specified criteria in the given location. You can use find <folder-to-search> -name <file-name>
its ‘-name’ option to make a case sensitive search and find <folder-to-search> -iname <file-name>
to make a case-insensitive search for files with the given file names.
find <folder-to-search> -iname <file-name>
tar
This command creates, views and extracts tar archives. You can use tar -cvf <archive-name.tar> <file1-OR-file2-OR-both-to-archive>
to create,tar -tvf <archive-to-view.tar>
to view and tar -xvf <archive-to-extract.tar>
to extract tar archives.
gzip
gzip <filename>
creates and extracts gzip archives. You can use its gzip -d <filename>
to extract gzip archives.
unzip
unzip <archive-to-extract.zip>
unzips a given zip archive. You can use unzip -l <archive-to-extract.zip>
to view the contents of the zip file without extracting it. It’s the same as you using an archive program to extract zip archives in GUI.
help
<command-name> --help
lists all the available commands in the terminal. You can use ‘-h’ or ‘–help’ (help has two hyphens here) option with any command to get help for that specific command.
whatis – What is this command
whatis <command-name>
shows a single-line description for the given command.
man – Manual
man <command-name>
shows the manual page for the given command.
exit
exit
ends the current terminal (bash) session. It’s the same as you clicking on the close button in the title bar of any application to close that application in GUI.
ping
ping <remote-host-address>
pings a remote host (server) by sending ping packets. It can be used to check for network connectivity or the status (up and running or otherwise) of a server. It’s the same as you pinging a host using the network manager in GUI.
who – Who Is logged in
who
shows the list of currently logged in users.
su – Switch User
su <username>
switches to a different user. Super user (root) can switch to any other user in the terminal even without using their password.
uname
uname
shows important information about your system such as kernel name, host name, kernel release number, processor type and various others. You can use uname -a
to view all information.
free – Free memory
free
shows information about the free, used, swap memory available (or currently free) in your system. You can use free -m
to view memory in KBs and free –g
to view memory in GBs.
df – Disk space Free
df
shows information about the file system’s disk space usages – used and available storage space on your hard disk and other storage devices. You can use df -h
to view the space usages in human readable form (i.e. memory in GBs).
ps – ProcesseS
ps
displays information about the running processes of the system.
Top – TOP processes
top
shows information about the top processes in the system (sorted by CPU usage by default). You can use top -u <username>
to view the top processes of a single user. It’s the same as you viewing the list of the most resource-hungry running processes using some task manager in GUI.
shutdown
shutdown
shuts down your computer. You can use shutdown -r
to restart your computer.
Did you use or practice some of these commands? Do you know any other useful Linux command for beginners? Kindly let us know using the comments section.
Now Read:
9 Linux Commands & Codes to be Wary of
29 Linux Commands You Must Know
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.