Basic Commands
Command | Description | Example |
---|---|---|
pwd | Print working directory | pwd |
cd | Change directory | cd /home/user/documents |
ls | List directory contents | ls -l |
mkdir | Make directory | mkdir my_folder |
touch | Create new file | touch my_file.txt |
cp | Copy file | cp my_file.txt my_file_copy.txt |
mv | Move or rename file | mv my_file.txt my_folder/my_file.txt |
rm | Remove file | rm my_file.txt |
User Management Commands
Command | Description | Example |
---|---|---|
whoami | Print current user | whoami |
id | Print user and group IDs | id |
adduser | Add new user | adduser newuser |
usermod | Modify user | usermod -aG sudo newuser |
deluser | Delete user | deluser newuser |
passwd | Change password | passwd |
File Permissions
Command | Description | Example |
---|---|---|
chmod | Change file permissions | chmod 755 my_file.txt |
chown | Change file owner | chown newuser my_file.txt |
chgrp | Change file group | chgrp users my_file.txt |
Input/Output Redirection
Command | Description | Example |
---|---|---|
> | Redirect output to file | ls > files.txt |
>> | Append output to file | ls >> files.txt |
< | Redirect input from file | sort < files.txt |
| | Pipe output to another command | ls | grep txt | sort -r List all files in current directory, search files with “txt” in their name, and then sort the results in reverse alphabetical order. |
Advanced Commands
Command | Description | Examples |
---|---|---|
awk | a programming language used for text manipulation and data extraction | awk '/search pattern/ { action }' input_file : searches the input file for the specified search pattern and performs the specified action |
sed | a stream editor used for text manipulation | sed 's/search pattern/replacement text/' input_file > output_file : searches the input file for the specified search pattern and replaces it with the specified replacement text, then saves the result to the output file |
grep | a search tool used to find specific patterns in text | grep 'search pattern' input_file : searches the input file for the specified search pattern and displays the matching lines |
find | a command used to search for files in a directory tree | find /path -name 'pattern' : searches the specified path for files with names that match the specified pattern |
xargs | a command used to build and execute commands from standard input | `ls |
tar | a command used to create, maintain, and extract files from a tar archive | tar -cvf archive.tar file1 file2 : creates an archive named archive.tar containing the specified files |
gzip | a command used to compress and decompress files | gzip file : compresses the specified file |
bzip2 | a command used to compress and decompress files | bzip2 file : compresses the specified file |
gunzip | a command used to decompress gzip files | gunzip file.gz : decompresses the specified gzip file |
bunzip2 | a command used to decompress bzip2 files | bunzip2 file.bz2 : decompresses the specified bzip2 file |
zcat | a command used to view the contents of a compressed file | zcat file.gz : displays the contents of the specified gzip file |