Notifications
Clear all

Linux Commands Cheat Sheet - File Operations


(@scriptguru)
Byte Beginner
Joined: 9 months ago
Posts: 24
Topic starter  

Here's a detailed "Linux Commands Cheat Sheet" focused specifically on File Operations, ranging from basic to advanced commands.

Command Description
ls List the files and directories within the current directory.
ls -l List files and directories with detailed information including permissions, number of links, owner, group, size, and time of last modification.
ls -a List all files and directories, including hidden ones (those whose names start with a dot).
cd directory Change the current directory to directory.
pwd Print the working directory, i.e., show the path of the current directory.
mkdir directory Create a new directory named directory.
rmdir directory Remove an empty directory named directory.
rm file Delete a file. Use with caution as this permanently removes the file.
rm -r directory Recursively remove a directory and its contents. Be very cautious with this command.
rm -f file Forcefully remove a file without prompting for confirmation.
cp source destination Copy the file or directory source to destination.
cp -r source_directory destination_directory Recursively copy a directory and its entire subtree.
mv source destination Move or rename source to destination. This command can be used for files or directories.
touch file Create an empty file or update the access and modification times of file to the current time.
cat file Display the content of file on the terminal.
less file View the content of file one page at a time. Allows backward and forward movement through the file.
head file Output the first 10 lines of file. Use -n to specify a different number of lines.
tail file Output the last 10 lines of file. Use -n to specify a different number of lines. Use -f to follow the file's growth.
ln -s target linkname Create a symbolic link named linkname to target.
chmod permissions file Change the permissions of file to permissions, which can be specified in symbolic or numeric mode.
chown user:group file Change the owner of file to user and the group to group.
find /path/to/search -name 'filename' Search for files or directories within the specified path that match the given filename pattern.
grep 'pattern' files Search for a specific pattern within files and output the lines that contain the pattern.
diff file1 file2 Compare file1 and file2 line by line and output the differences.
tar -cvf archive.tar files Create an archive named archive.tar containing files.
tar -xvf archive.tar Extract the contents of archive.tar.
zip -r archive.zip files Create a zip archive named archive.zip containing files.
unzip archive.zip Extract the contents of archive.zip.

This cheat sheet covers a wide range of file operation commands in Linux, from basic commands for listing and navigating directories, to more advanced operations like file searching, comparison, and archiving.


   
Quote
Share: