ls - The most frequently used command in Linux to list directories
pwd - Print working directory command in Linux
cd - Linux command to navigate through directories
mkdir - Command used to create directories in Linux
mv - Move or rename files in Linux
cp - Similar usage as mv but for copying files in Linux
rm - Delete files or directories
touch - Create blank/empty files
ln - Create symbolic links (shortcuts) to other files
cat - Display file contents on the terminal
clear - Clear the terminal display
echo - Print any text that follows the command
less - Linux command to display paged outputs in the terminal
man - Access manual pages for all Linux commands
uname - Linux command to get basic information about the OS
whoami - Get the active username
tar - Command to extract and compress files in Linux
grep - Search for a string within an output
head - Return the specified number of lines from the top
tail - Return the specified number of lines from the bottom
diff - Find the difference between two files
cmp - Allows you to check if two files are identical
comm - Combines the functionality of diff and cmp
sort - Linux command to sort the content of a file while outputting
export - Export environment variables in Linux
zip - Zip files in Linux
unzip - Unzip files in Linux
ssh - Secure Shell command in Linux
service - Linux command to start and stop services
ps - Display active processes
kill and killall - Kill active processes by process ID or name
df - Display disk filesystem information
mount - Mount file systems in Linux
chmod - Command to change file permissions
chown - Command for granting ownership of files or folders
ifconfig - Display network interfaces and IP addresses
traceroute - Trace all the network hops to reach the destination
wget - Direct download files from the internet
ufw - Firewall command
iptables - Base firewall for all other firewall utilities to interface with
apt, pacman, yum, rpm - Package managers depending on the distro
sudo - Command to escalate privileges in Linux
cal - View a command-line calendar
alias - Create custom shortcuts for your regularly used commands
dd - Majorly used for creating bootable USB sticks
whereis - Locate the binary, source, and manual pages for a command
whatis - Find what a command is used for
top - View active processes live with their system usage
useradd and usermod - Add new user or change existing users data
passwd - Create or update passwords for existing users
further variations:-
Let's dive deep into the commands...
pwd
displays your present working directory/current directory
cd
used to change your current directory
cd..
it takes us to the parent directory
(base) dazaisan@MSI-Modern-14-A10RAS:~/Downloads$ pwd
/home/dazaisan/Downloads
(base) dazaisan@MSI-Modern-14-A10RAS:~/Downloads$ cd ..
(base) dazaisan@MSI-Modern-14-A10RAS:~$ pwd
/home/dazaisan
cd -
it takes us to the previous directory
(base) dazaisan@MSI-Modern-14-A10RAS:~/Downloads$ pwd
/home/dazaisan/Downloads
(base) dazaisan@MSI-Modern-14-A10RAS:~/Downloads$ cd ..
(base) dazaisan@MSI-Modern-14-A10RAS:~$ pwd
/home/dazaisan
(base) dazaisan@MSI-Modern-14-A10RAS:~$ cd -
/home/dazaisan/Downloads
ls
it lists the contents of the directory in which it is used
ls -a
it shows all the hidden files
ls -l
lists the permissions of the files and directories as well as other attributes such as folder names, file and directory sizes, and modified date and time
ls -r
lists files in reverse order
ls -lh
used to easily identify the file sizes as kilobytes (kB), Megabytes (MB) or Gigabytes (GB)
ls -R
used to display the directory trees of files and folders
ls -F
used to distinguish files from directories
dazaisan@MSI-Modern-14-A10RAS:~$ls -F
a1.c a.out* Documents/ mysql p1.out* p3.c Pictures/ snap/ add.tcl cn1.tcl Downloads/ out.nam p2.c p3.cpp Public/ Templates/ anaconda3/ Desktop/ Music/ p1.c p2.out* p4.c q1.c Videos/
ls -i
it is used to display the inode number of files and directories
ls -n
used when you want to display the UID as well as the GId of files and directories
ls --v
for ls version
ls --help
to view options about what you can do with lsalias and unalias
(base) dazaisan@MSI-Modern-14-A10RAS:~$ alias
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '''s/^\s*[0-9]+\s*//;s/[;&|]\salert$//''')"' alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias grep='grep --color=auto' alias l='ls -CF' alias la='ls -A' alias ll='ls -alF' alias ls='ls --color=auto'
(base) dazaisan@MSI-Modern-14-A10RAS:~$ unalias la #la alias is removed
(base) dazaisan@MSI-Modern-14-A10RAS:~$ alias
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '''s/^\s[0-9]+\s*//;s/[;&|]\s*alert$//''')"' alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias grep='grep --color=auto' alias l='ls -CF' alias ll='ls -alF' alias ls='ls --color=auto'
man ls
manual for ls command uses is displayed.
mkdir
used to make a new directory, at least one parameter is needed which is the name of the new directory to be created.mkdir -p
it solves the following problem
dazaisan@MSI-Modern-14-A10RAS:~/Desktop$ mkdir test/linux/t1 mkdir: cannot create directory ‘test/linux/t1’: No such file or directory
The command fails because the parent directory of threedirsdeep does not exist.
the option -p, then mkdir will create parent directories as needed.
(base) dazaisan@MSI-Modern-14-A10RAS:~/Desktop$ mkdir -p test/linux/t1
using -p, there will be no issue while creating a new directory inside a directory which doesn't exist as the new directories are created as per the requirementrmdir
it is used to remove the directory. Parameter has the path of the directory to be removed.
Note: The directory should be empty before using this command
rmdir -p
to recursively remove directories. it deletes multiple directories at once.
Note: The directory should be empty before using this commandI'll keep updating commands as i encounter the new one's. Thanks for reading :)
I have tried to add some extra stuffs in Knowledge stack section
Knowledge Stack:
An inode is a data structure that keeps track of all the files and directories within a Linux or UNIX-based filesystem. So, every file and directory in a filesystem is allocated an inode, which is identified by an integer known as an “inode number”. These unique identifiers store metadata about each file and directory. All inodes within the same filesystem are unique.
Each inode is identified by an inode number. Therefore, when creating or copying a file, Linux assigns a different inode number to the new file. However, when moving a file, the inode number will only change if the file is moved to a different filesystem. This applies to directories as well.
Use df-i to pull basic data about your inode usage, including the file system on which the inodes are stored, your total inode count, how many are in use (in count and %), and how many remain.
To check the number of inodes in a directory, the
wc
command is used to count the number of characters, words, lines and bytes of files. Together with the-l
option, you can use it to count the number of inodes in a directoryto check inode uses, https://www.2daygeek.com/linux-check-count-inode-usage/
Counting inod enumber with grand total
(base) dazaisan@MSI-Modern-14-A10RAS:~$ echo "Detailed Inode usage for: $(pwd)" ; for d in find -maxdepth 1 -type d |cut -d\/ -f2 |grep -xv . |sort; do c=$(find $d |wc -l) ; printf "$c\t\t- $d\n" ; done ; printf "Total: \t\t$(find $(pwd) | wc -l)\n"
Detailed Inode usage for: /home/dazaisan 171545 - anaconda3 4 - .anydesk 50892 - .cache 2 - .conda 25716 - .config 3327 - Desktop 2 - Documents 8 - .dotnet 2 - Downloads 3 - .gnupg 1 - .gphoto 16 - .java 3604 - .local 12 - .minikube 2 - .mozilla 1 - Music 21 - .npm 17 - .openshot_qt 25 - Pictures 5 - .pki 1 - Public 4 - .rpmdb 12982 - snap 1 - .ssh 1 - Templates 114 - .thunderbird 2 - Videos 7204 - .vscode 67 - .zoom Total: 275604
Metadata stored in an inode
Inodes store metadata such as:
File type
File size
Owner ID
Group ID
Read, write and execute permissions
Last access time
Last change time
Last modification time
Excessive inode usage can lead to issues when creating new files and directories. Some of the issues users may encounter when the server runs out of inodes are:
Data loss.
Server restart.
Application crash.
Scheduled tasks not running.
So, it is recommended to keep inode usage low by deleting:
Unnecessary files and directories.
Cache files.
Old email files.
Temporary files.
- In a Unix system, a GID (group ID) is a name that associates a system user with other users sharing something in common (perhaps a work project or a department name). It's often used for accounting purposes. A user can be a member of more than one group and thus have more than one GID. Any user using a UNIX system at a given time has both a user ID (UID) and a group ID (GID).
PRACTICE EXERCISE reference Linux Fundamentals- Paul Cobbaut
Display your current directory.
Change to the /etc directory.
Now change to your home directory using only three key presses.
Change to the /boot/grub directory using only eleven key presses.
Go to the parent directory of the current directory.
Go to the root directory.
List the contents of the root directory.
List a long listing of the root directory.
Stay where you are, and list the contents of /etc.
Stay where you are, and list the contents of /bin and /sbin.
Stay where you are, and list the contents of ~.
List all the files (including hidden files) in your home directory.
List the files in /boot in a human readable format.
Create a directory testdir in your home directory.
Change to the /etc directory, stay here and create a directory newdir in your home directory.
Create in one command the directories ~/dir1/dir2/dir3 (dir3 is a subdirectory from dir2, and dir2 is a subdirectory from dir1 ).
Remove the directory testdir.
If time permits (or if you are waiting for other students to finish this practice), use and understand pushd and popd. Use the man page of bash to find information about these commands
solution: working with directories
Display your current directory.
pwd
Change to the /etc directory.
cd /etc
Now change to your home directory using only three key presses.
cd (and the enter key)
Change to the /boot/grub directory using only eleven key presses.
cd /boot/grub (use the tab key)
Go to the parent directory of the current directory.
cd .. (with space between cd and ..)
Go to the root directory.
cd /
List the contents of the root directory.
ls
List a long listing of the root directory.
ls -l
Stay where you are, and list the contents of /etc.
ls /etc
Stay where you are, and list the contents of /bin and /sbin.
ls /bin /sbin
Stay where you are, and list the contents of ~.
ls ~
List all the files (including hidden files) in your home directory.
ls -al ~
List the files in /boot in ahuman readable format. ls -lh /boot 14. Create a directory testdir in your home directory. mkdir ~/testdir 15. Change to the /etc directory, stay here and create a directory newdir in your home directory.
cd /etc ; mkdir ~/newdir
Create in one command the directories ~/dir1/dir2/dir3 (dir3 is a subdirectory from dir2, and dir2 is a subdirectory from dir1 ).
mkdir -p ~/dir1/dir2/dir3
Remove the directory testdir.
rmdir testdir
If time permits (or if you are waiting for other students to finish this practice), use and understand pushd and popd. Use the man page of bash to find information about these commands.
man bash # opens the manual
/pushd # searches for pushd
n # next (do this 2-3 times)
The Bash shell has two built-in commands called pushd and popd. Both commands work with a common stack of previous directories. Pushd adds a directory to the stack and changes to a new current directory, popd removes a directory from the stack and sets the current directory.
paul@debian7:/etc$ cd /bin
paul@debian7:/bin$ pushd /lib
/lib /bin
paul@debian7:/lib$ pushd /proc
/proc /lib /bin
paul@debian7:/proc$ popd
/lib /bin
paul@debian7:/lib$ popd
/bin
References:
[2] https://www.techtarget.com/whatis/definition/GID-group-ID-or-global-index-file
[3] https://www.digitalocean.com/community/tutorials/linux-commands