Searching

Search for a specific pattern in a file with:

grep [pattern] [file_name]
Recursively search for a pattern in a directory:

grep -r [pattern] [directory_name]
Find all files and directories related to a particular name:

locate [name]
List names that begin with a specified character [a] in a specified location [/folder/location] by using the find command:

find [/folder/location] -name [a]
See files larger than a specified size [+100M] in a folder:

find [/folder/location] -size [+100M]
File Commands
List files in the directory:

ls
List all files (shows hidden files):

ls -a
Show directory you are currently working in:

pwd
Create a new directory:

mkdir [directory]
Remove a file:

rm [file_name]
Remove a directory recursively:

rm -r [directory_name]
Recursively remove a directory without requiring confirmation:

rm -rf [directory_name]
Copy the contents of one file to another file:

cp [file_name1] [file_name2]
Recursively copy the contents of one file to a second file:

cp -r [directory_name1] [directory_name2]
Rename [file_name1] to [file_name2] with the command:

mv [file_name1] [file_name2]
Create a symbolic link to a file:

ln -s /path/to/[file_name] [link_name]
Create a new file:

touch [file_name]
Show the contents of a file:

more [file_name]
or use the cat command:

cat [file_name]
Append file contents to another file:

cat [file_name1] >> [file_name2]
Display the first 10 lines of a file with:

head [file_name]
Show the last 10 lines of a file:

tail [file_name]
Encrypt a file:

gpg -c [file_name]
Decrypt a file:

gpg [file_name.gpg]
Show the number of words, lines, and bytes in a file:

wc

Leave a Reply

Your email address will not be published. Required fields are marked *