Linux Commands - Step-by-Step Explanation and Commands
---
1. Check Current Working Directory
Explanation: pwd shows the full path of the current directory you are in.
Command:
pwd
2. List Files in Current Directory
Explanation: ls lists the files and folders in the current directory.
Command:
ls
3. Typo/Invalid Command
Explanation: l. is not a valid command.
Command:
l.
(Will give an error.)
4. List All Files Including Hidden Files
Explanation: ls -a lists all files, including hidden files.
Command:
ls -a
5. List Files in Human-Readable Form
Explanation: ls -lh lists files showing size in human-readable format.
Command:
ls -lh
6. List Only Directory Details
Explanation: Syntax is slightly wrong, should be corrected to ls -ldh .
Command:
ls -lhd
7. Create Directory d1
Explanation: mkdir d1 creates a directory.
Command:
mkdir d1
8. Create Directories d2 and d3
Explanation: Creates two directories at once.
Command:
mkdir d2 d3
9. Create Empty File 1.txt
Explanation: Creates an empty file.
Command:
touch 1.txt
10. Create Files 2.pdf and 3.html
Explanation: Creates two empty files.
Command:
touch 2.pdf 3.html
11. Check File Types
Explanation: Checks type of content in files.
Command:
file 2.pdf 3.html
12. Create Directory /usr/d1
Explanation: Creates a directory under /usr (requires sudo).
Command:
mkdir /usr/d1
13. Create Directories /usr/d2 and /etc/default/d3
Explanation: Creates multiple directories.
Command:
mkdir /usr/d2 /etc/default/d3
14. Create Nested Directory Structure
Explanation: Creates all parent directories needed.
Command:
mkdir -p /linux/distros/redhat
15. Create Multiple Directories at Once
Explanation: Creates ubuntu, centos, and fedora inside /linux/distros.
Command:
mkdir /linux/distros/{ubuntu,centos,fedora}
16. View Directory Structure as Tree
Explanation: Displays tree view of /linux directory.
Command:
tree /linux
17. Create Multiple Files at Once
Explanation: Creates 1.txt, 2.txt, 3.txt under /usr.
Command:
touch /usr/{1.txt,2.txt,3.txt}
18. Copy File to Another Directory
Explanation: Copies 1.txt to /linux/distros/redhat.
Command:
cp /usr/1.txt /linux/distros/redhat
19. Copy Directory Recursively
Explanation: Copies d1 into redhat.
Command:
cp -r /usr/d1 /linux/distros/redhat
20. Move File to Another Directory
Explanation: Moves 2.txt to redhat.
Command:
mv /usr/2.txt /linux/distros/redhat
21. Move Directory to Another Location
Explanation: Moves d2 into redhat.
Command:
mv /usr/d2 /linux/distros/redhat
22. Remove All .txt Files in Directory
Explanation: Force deletes all .txt files inside redhat.
Command:
rm -f /linux/distros/redhat/*.txt
23. Remove Multiple Directories Recursively
Explanation: Deletes /linux and directories d1, d2.
(Note: Typo in distors, should be distros.)
Command:
rm -rf /linux /linux/distors/redhat/{d1,d2}
---
Summary
Practiced viewing, creating, copying, moving, and deleting files/directories; using wildcards and
recursion; and organizing the Linux filesystem.