Basic Commands with explanation
Basic Commands with explanation
1.ls
ls
Output:
2. ls -a
Purpose: Lists all files, including hidden files (those starting with a dot .).
Example:
ls -a
Output:
3. ls -l
ls -l
Output:
4. ls -l collection/
ls -l collection/
Output:
-rw-r--r-- 1 user user 512 Jan 24 doc1.txt
drwxr-xr-x 2 user user 4096 Jan 24 images
5. ls -ld collection/
Purpose: Displays detailed information about the collection/ directory itself, not
its contents.
Example:
ls -ld collection/
Output:
6. ls -i
ls -i
Output:
7. ls -lt /home/student/
bash
ls -lt /home/student/
Output:
8. ls -ltr /home/student/
Output:
9. ls -sh /home/student/
ls -sh /home/student/
Output:
10. ls -s /boot
Purpose: Displays the size of each file in blocks (default block size).
Example:
ls -s /boot
Output:
32 config-5.11.0 64 initrd.img
11. ls -R /boot
ls -R /boot
Output:
/boot:
config-5.11.0 initrd.img
/boot/grub:
menu.lst
12. ls -R /home/
Output:
/home/user:
documents downloads
/home/user/documents:
file1.txt file2.pdf
Purpose: Displays the directory structure in a tree-like format. (You may need to
install tree first.)
Example:
tree /home
Output:
/home
├── documents
├── downloads
└── pictures
14. history
history
Output:
1 ls
2 cd /home
3 pwd
cd /etc
pwd
Output:
/etc
cd ..
pwd
Output:
cd ~
pwd
Output:
/root
cd collection
pwd
Output:
/root/collection
3. Paths
Absolute Path:
Example:
cd /root/collection
pwd
Output:
/root/collection
Relative Path:
Example:
cd collection
pwd
Output:
/root/collection
touch app
ls
Output:
app
Output:
touch app{1..5}.txt
ls
Output:
mkdir project
ls
Output:
project
Create multiple directories at once:
Example:
Output:
mkdir -p office/departments/{Sales,Marketing,Accounts}
ls office/departments
Output:
cp app1.txt dir1/
ls dir1
Output:
app1.txt
Output:
app2.txt app3.txt
cp -r dir1 dir3/
ls dir3
Output:
dir1
mv app4.txt dir2/
ls dir2
Output:
Rename a file:
Example:
mv app5.txt renamed_app5.txt
ls
Output:
renamed_app5.txt
Delete a file:
Example:
rm app1.txt
ls
Output:
app2.txt app3.txt
rm app2.txt app3.txt
ls
Output:
dir1 dir2
Delete a directory and its contents:
Example:
rm -r dir1
ls
Output:
dir2