Creating Files and Directories

CommandDescription
touch file.txtCreates an empty file named file.txt.
mkdir new_directoryCreates a new directory named new_directory.
echo "text" > file.txtCreates a file with the specified text content.
echo "text" >> file.txtAppends the specified text to an existing file.

Viewing and Editing Files

CommandDescription
cat file.txtDisplays the entire content of a file.
head file.txtDisplays the first 10 lines of a file.
head -n 5 file.txtDisplays the first 5 lines of a file.
tail file.txtDisplays the last 10 lines of a file.
nano file.txtOpens file.txt in the nano text editor.

File Search Techniques

CommandDescription
find /path -name filenameSearches for a file with the specified name under the given path.
find . -type dSearches for all directories in the current path.
find . -type f -name "*.txt"Finds all .txt files in the current directory.
which commandLocates the executable path of a command.

Deleting Files

rm: Deletes files or directories.

CommandDescription
rm file.txtdeletes a file named file.txt
rm -i file.txtprompts before deleting the file
rm -r folderdeletes a folder and its contents
rm -rf folderforcibly deletes a folder and its contents without confirmation

Caution: Use the -f (force) option carefully, as it bypasses confirmation.


Copying Files

cp: Copies files or directories.

CommandDescription
cp file.txt backup.txtcopies file.txt to backup.txt
cp -r folder1 folder2recursively copies folder1 and its contents to folder2
cp -i file.txt backup.txtprompts before overwriting backup.txt

Moving Files

mv: Moves or renames files and directories.

CommandDescription
mv file.txt folder/moves file.txt to the folder
mv oldname.txt newname.txtrenames oldname.txt to newname.txt
mv -i file.txt folder/prompts before overwriting a file in the destination