Introduction to commands and working with files and directories
Syntax of commands :
#command [options] <arguments>
Manual pages for commands, files and services.
#man cd
#man lsblk
#man rsyslog.conf
#man sshd
for seeing only description of a command we use
#whatis cd
#whatis route (before using this, use mandb)
for seeing all binary file location of any command use
#whereis route
#whereis cd
for seeing only the options for a particular command or service use
- #lsblk --help
Working with directories :
pwd : present working directory
→ shows where are you working right now
cd : change directory
→ cd [Destination]
→To go in home directory from any other location use → #cd
→To go in previous location from current location use → #cd -
cd . → takes to current directory
cd .. → takes to parent directory
Now list the directories without going to them
#ls → for list
#ls -a → include hidden files/directories also with all
#ls -l → long listing
#ls -al → All files / directories in long listing format
#ls -alh → long listing with human readable format
Make and remove directories
#mkdir : to make directory
#mkdir /data
#mkdir -p /a/b/c/d/e : If you want to make directory under directory, -p indicates parent-child structure
to check #ls -ld /a/b/c/d/e
for removing empty directories
→ #rmdir /a/b/c/d/e
for removing non-empty directories
→ #rm -rf /a/b/c/d/e
Multiple commands execution in single line
#date
#cal
OR
#date ; cal ; echo “; is used for commands separation and sequential execution“
Working with files :
Make and remove files
#touch linux.txt
#ls -li
→ i for inode number which is used for unique number representation for each file
Every thing in linux is considered as file
#ls -l /dev/sda
To check the type of a file
→ #cal > cal.txt
→ file cal.txt
→ #cat cal.txt
→ file /dev/sda
Creating multiple files with one command
→ #touch java{2..36}.txt
→ #ll
→ touch anaconda-ks.cfg (will change the time if file already exist)
Creating file with specified time using touch
→ touch -t 202512100615 anakonda-ks.cfg (2025-12-10 06:15)
Removing files
→ #rm cal.txt (for empty file deletion)
→ #rm -rf cal.txt (for non-empty file deletion)
Copy and Move/Rename files & directories :
Copy files and directories
Syntax
→ #cp [source] [destination]
→ #cp a1.txt /tmp/new.txt
→ #cp -r /var/log/messages /tmp/Linux/mess.txt (-r → recursively)
Move/Rename files and directories
Syntax
→ #mv [source] [destination]
→ #mv abc.txt /tmp
→ #cd /tmp
→ #ll
To Manage contents of a file
cat : used for full file contents visibility and also for creating new files
→ #cat abc.txt
→ #cat > newfile.txt (overrides the data)
→ #cat >> newfile.txt (appends the data)
head : used for starting lines of a file
→ #head -15 /etc/passwd
→ #head /etc/passwd (by default 10 lines)
tail : used for ending lines of a file
→ #tail -15 /etc/passwd
→ #tail /etc/passwd (by default 10 lines)
echo : for printing any string/text on the terminal
→ #echo “hii“
more : for reading file up to down
→ #more /var/log/messages
less : for reading file in less format
→ #more /var/log/messages
strings : binary files cannot be opened / viewed using cat command so, we use strings command
→ #strings zsh