Shell commands for file management:
-
ls:
- Example: ls
- Description: Lists files and directories in the current directory.
-
cd:
- Example: cd /path/to/directory
- Description: Changes the current directory to the specified directory.
-
pwd:
- Example: pwd
- Description: Prints the current working directory.
-
mkdir:
- Example: mkdir new_directory
- Description: Creates a new directory with the specified name.
-
rmdir:
- Example: rmdir empty_directory
- Description: Removes an empty directory.
-
rm:
- Example: rm file.txt
- Description: Removes a file.
-
touch:
- Example: touch file.txt
- Description: Creates an empty file or updates the timestamp of an existing file.
-
cp:
- Example: cp file.txt /path/to/destination
- Description: Copies a file to the specified destination.
-
mv:
- Example: mv file.txt /path/to/destination
- Description: Moves a file to the specified destination or renames a file.
-
cat:
- Example: cat file.txt
- Description: Displays the contents of a file.
-
less:
- Example: less file.txt
- Description: Displays the contents of a file one page at a time.
-
head:
- Example: head -n 10 file.txt
- Description: Displays the first few lines (default: 10 lines) of a file.
-
tail:
- Example: tail -n 5 file.txt
- Description: Displays the last few lines (default: 10 lines) of a file.
-
grep:
- Example: grep "pattern" file.txt
- Description: Searches for a pattern in a file.
-
find:
- Example: find /path/to/directory -name "file.txt"
- Description: Searches for files and directories matching specific criteria.
-
chmod:
- Example: chmod 755 file.txt
- Description: Changes the permissions of a file or directory.
-
chown:
- Example: chown user:group file.txt
- Description: Changes the owner and group of a file or directory.
-
chgrp:
- Example: chgrp group file.txt
- Description: Changes the group of a file or directory.
-
ln:
- Example: ln -s source_file.txt link.txt
- Description: Creates a symbolic link to a file or directory.
-
file:
- Example: file file.txt
- Description: Determines the file type.
-
du:
- Example: du -sh directory
- Description: Estimates the disk space usage of a file or directory.
-
df:
- Example: df -h
- Description: Displays disk space usage of file systems.
-
zip:
- Example: zip archive.zip file1.txt file2.txt
- Description: Creates a compressed zip archive.
-
unzip:
- Example: unzip archive.zip
- Description: Extracts files from a zip archive.
-
tar:
- Example: tar -czvf archive.tar.gz directory
- Description: Creates or extracts files from a tar archive.
-
wc:
- Example: wc -l file.txt
- Description: Counts the number of lines, words, and characters in a file.
-
sort:
- Example: sort file.txt
- Description: Sorts lines in a file.
-
cut:
- Example: cut -f 2,4 -d ',' file.txt
- Description: Cuts out selected fields or columns from a file.
-
paste:
- Example: paste file1.txt file2.txt
- Description: Merges lines from multiple files.
-
diff:
- Example: diff file1.txt file2.txt
- Description: Compares files line by line.
These are some commonly used shell commands for file management, along with examples to illustrate their usage.