0% found this document useful (0 votes)
17 views

Basic Linux Commands

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Basic Linux Commands

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1) man

• Returns the manual paper of the . Ex. man cd


COMMANDS RELATED TO FILE SYSTEM
2) pwd [ pwd == print working directory ]
• Returns the location of current/working directory.
3) cd
• Moves to specified directory.
(a) cd /home Takes to the home directory.
(b) cd / ‘OR’ cd Takes to the root directory.
(c) cd / ‘OR’ cd Takes to the directory.
(d) cd .. Takes to the parent directory of the current directory.
4) ls
• Lists all the files and folders present in the current directory.
(a) ls Lists Unhiddens files and folders.
(b) ls -a Lists All files and folders.
(c) ls -l Lists Unhidden files and folders in detailed format.
(d) ls -h Lists Unhidden files and folders in human readable format.
(e) ls -la Lists All files and folders in detailed format.
(f) ls -lh Lists Unhidden files and folders in detailed and human readable
format.
(g) ls -lah Lists All files and folders in detailed and human readable
format.
5) clear
• Moves all content upwards making screen look clean.
6) mkdir
• Creates a directory.
(a) mkdir Creates a directory with the name inside current directory.
(b) mkdir -p // Creates a parent directory and its child directory. We
would see the following structure- > directoryname_1 > directory-
name_2 directoryname_3
7) rmdir
• Removes an empty directory.
(a) rmdir Removes the directory with the name if it is empty.
(b) mkdir -p // Removes the entire parent - child directory starting from
the child directory and checking if it is empty or not.
8) file
• Shows the details and properties of the file .
9) touch
• Creates multiple empty files in the same directory.
10) rm
• Deletes file and folder.
(a) rm ‘OR’ rm Deletes the specified files.
(b) rm -i [ i == Interactive Mode ] Asks for conformation before moving
the file
(c) rm -rf [ rm == Recursive Enforce ] Deletes the directory whether

1
empty or not.
11) cp
• Makes copies of specified file or folder.
(a) cp Creates a copy of with the name in the same directory.
(b) cp Creates a copy of at the location .
(c) cp -r Creates a copy of the entire folder named at the location .
12) mv
• Rename a file or folder.
• Move a file and folder.
(a) mv Renames the file or folder name from to .
(b) mv Moves the specified file or folder to the specified location.
13) head
• Outputs first 10 lines of a file to the console.
(a) head Prints first 10 lines of the file to the console/terminal.
(b) head - Prints first lines of the file to the console/terminal.
14) tail
• Outputs last 10 lines of a file to the console.
(a) tail Prints last 10 lines of the file to the console/terminal.
(b) head - Prints last lines of the file to the console/terminal.
15) cat
• Outputs entire file to the console.
• Concatinates two files into one file.
• Creates a file whose content can be written using terminal.
• Creates a copy of a specified file with the specified name.
(a) cat Prints all the lines of the file to the console/terminal.
(b) cat Prints content of all the files to the console/terminal.
(c) cat > Creates a new file named which has the content of all the above
three files.
(d) cat > Creates a file named and then the terminal prompts the user to
enter file content. Press ‘Enter’ button can be used to put multiple
lines in file. Press ‘Ctrl + d’ 2 times to save the file and exit the
prompt.
(e) cat > Creates a copy of the file and saves it with the name .
16) echo
• Creates a one line file with the content provided.
(a) echo > Makes a new file named having . If same name file exits then
it will be deleted and the new file will be created.
17) more
• Displays an entire file in form of pages.
(a) more Displays the content of the file on full terminal screen and for
those content which can not be fitted in screen, it is shown on next
pages. Next page can be accessed by hitting the ‘spacebar’. Pressing
‘q’ will quit from viewing the file.
18) less
• Displays an entire file in form of pages with more features.
(a) less Displays the content of the file on full terminal screen and for

2
those content which can not be fitted in screen, it is shown on next
pages. Next page can be accessed by hitting the ‘spacebar’. We can
also move to individual lines by hitting ‘up’ and ‘down’ keys. Pressing
‘q’ will quit from viewing the file.
19) ip a
• It displays information about the network, ip address, etc.
COMMANDS RELATED TO PROCESS MONITOR
20) uptime
• It returns the current time, the duration of time system has been up,
number of users, and load on the system.
21) free
• Displays information about the memory or storage.
22) ps
• Displays all the current running processes in the system.
(a) ps -A Displays all the processes of the system.
23) top
• Displays the Linux processes with all the information. It is not in a
good readable form.
24) htop
• Displays the Linux processes with all the information in a more clear
and visually understandable form which is also user interactable.
• If ‘htop’ is not present, then we can install it by running the following
command - ‘sudo apt install htop’
• We can exit the ‘htop’ view by hitting ‘q’ key.
COMMANDS RELATED TO HARD DISK
25) df
• It displays the file system disk space usage.
26) sudo fdisk -l
• It gives information about the partitions of the hard drive on the
system.
27) lsblk
• It lists the block divices. It is another way of looking at the disks
connected to the system.
COMMANDS FOR PACKAGE MANAGER
28) sudo { sudo == superuser do }
• It temporarily allows users to do sensitive tasks without logging-in
as superuser.
• It requires your user password before you can run any command using
sudo previlages.
29) apt { apt == advanced package management tool }
• It is a command line package manager and provides commands for
searching and managing as well as querying information about pack-
ages.

3
30) Some mostly used commands with ‘sudo’ and ‘apt’ are listed below -
_____________________________________________________________
| COMMANDS USED WITH SUDO & APT | COMPLETE COM-
MANDS | |_______________________________________________________
| | | | list:- | | | • list packages based on package names | sudo apt list | |
search:- | | | • search in package descriptions | sudo apt search | | show:-
| | | • show package details | sudo apt show | | install:- | | | • install
packages | sudo apt install | | reinstall:- | | | • reinstall packages | sudo
apt reinstall | | remove:- | | | • remove packages | sudo apt remove | |
autoremove:- | | | • remove automatically all unused packages | sudo apt
autoremove | | update:- | | | • update list of available packages | sudo
apt update | | upgrade:- | | | • upgrade system by installing/upgrading
packages | sudo apt upgrade | | full-upgrade:- | | | • upgrade system
by removing/installing/upgrading packages | sudo apt full-upgrade | |
edit-sources:- | | | • edit the source information file | sudo apt edit-
sources | | satisfy:- | | | • satisfy dependency strings | sudo apt satisfy |
|____________________________________________________________|

You might also like