Most Commonly Used Shell Commands
1. ls
- List directory contents
- Lists files and directories in the current directory.
ls
ls -l # Long format
ls -a # Show hidden files
ls -lh # Human-readable sizes
2. cd
- Change directory
- Changes the current directory.
cd directory_name
cd .. # Move up one directory
cd ~ # Move to home directory
cd /path/to/directory # Absolute path
3. pwd
- Print working directory
- Displays the path of the current directory.
pwd
4. mkdir
- Make directory
- Creates a new directory.
mkdir directory_name
5. rm
- Remove
- Deletes files or directories.
rm filename
rm -r directory_name # Recursively remove directory
rm -f filename # Force remove without prompt
6. cp
- Copy
- Copies files or directories.
cp source_file destination_file
cp -r source_directory destination_directory # Recursive copy
7. mv
- Move
- Moves or renames files or directories.
mv source_file destination_file
mv old_name new_name # Rename
8. cat
- Concatenate and display
- Displays content of a file.
cat filename
9. grep
- Global Regular Expression Print
- Searches for a pattern in files.
grep "pattern" filename
grep -r "pattern" directory_name # Recursively search
10. echo
- Print
- Displays text on the terminal.
echo "Hello, World!"
11. chmod
- Change mode
- Changes permissions of files and directories.
chmod +x file # Add execute permission
chmod 755 file # Octal notation (rwxr-xr-x)
12. chown
- Change owner
- Changes the owner of files and directories.
chown user:group file
13. sudo
- Superuser do
- Executes a command with superuser privileges.
sudo command
14. top
- Display system processes
- Shows currently running processes.
top
15. df
- Display filesystem usage
- Shows disk space usage.
# Display Filesystem Usage in Human-readable Format
df -h
# Display Filesystem Type
df -T
# Display Inode Usage
df -i
# Output in POSIX Format
df -P
# Display Filesystem Usage with Type in Human-readable Format
df -hT