Essential Linux Commands for File and Directory Management
Listing Files with ls
Display all files and directories in the current working directory.
ls
List contents of a specific directory, using ./ for current or ../ for parenet.
ls path
Show detailed information in a long listing format.
ls -l path
ls -la path
In the output, the first character indicates file type: - for files, d for directories.
Present files in a list with human-readable sizes.
ls -lh
Printing the Current Directory with pwd
Output the absolute path of the current working directory.
pwd
Changing Directories with cd
Switch to a different directory.
cd path
Navigate to the current user's home directory.
cd ~
Creating Directories with mkdir
Make a new directory at the specified location.
mkdir path
Create multiple directories at once.
mkdir path1 path2 path3
Use the -p option to create nested directories that do not exist.
mkdir -p a/b/c
Creating Files with touch
Generate a new empty file or update timestamps of existing ones.
touch file_path
Create multiple files simultaneously.
touch file1.txt file2.txt file3.txt
Copying Files and Directories with cp
Duplicate a file to a new location, optionally renaming it.
cp source_path destination_path
To copy directories recursively, include the -r flag.
cp -r source_dir destination_dir
Moving and Renaming with mv
Relocate a file or directory to a new path.
mv source_path destination_path
Rename a file by moving it within the same directory with a new name.
mv old_name new_name
Removing Files and Directories with rm
Delete a file.
rm file_path
Remove a directory and its contents recursively with -r, and force deletion with -f.
rm -rf directory_path
Delete multiple files using widlcards, such as all files starting with 'linux'.
rm linux*
Editing Files with vim
Open a file in the vim text editor, creating it if it does not exist.
vim file_path
To exit vim without saving, press Shift + :, type q, and hit Enter.
Redirecting Output
Save command output to a file, overwriting existing content.
command > file_path
Append output to a file without overwriting.
command >> file_path
Viewing and Combining Files with cat
Display the contents of a file direct in the terminal.
cat file_path
Merge multiple files into a single file.
cat file1 file2 > merged_file