Skip to content

Instantly share code, notes, and snippets.

@albertodebortoli
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save albertodebortoli/8944025 to your computer and use it in GitHub Desktop.

Select an option

Save albertodebortoli/8944025 to your computer and use it in GitHub Desktop.
Linux Snippets

Linux - Snippets

by Marco Cattai

Searching

Search all the files/folder with that name and remove them

find . -name "FILE-TO-FIND"-exec rm -rf {} \;

Find all files having .bak (*.bak) extension in current directory and remove them

find . -type f -name "*.bak" -exec rm -f {} \;

Find all core files and remove them

find / -name core -exec rm -f {} \;

Find all *.bak files in current directory and removes them with confirmation from user

find . -type f -name "*.bak" -exec rm -i {} \;

Find all pdf files and copy them in DestinationFolder

find . -type f -name "*.pdf" -exec cp {} DestinationPath \;

Search for pattern in files

grep pattern files

Search recursively for pattern in dir

grep -r pattern dir

Search for pattern in the output of command

command | grep pattern

Starting with the root directory, look for the file called filename

find / -name filename

Starting with the root directory, look for the file containing the string filename

find / -name ”*filename*”

Starting with the directory called dir, look for and list all files containing TextStringToFind

grep TextStringToFind /dir

Create symbolic link link to file

ln -s file link

Create or update file

touch file

Places standard input into file

cat > file

Display the file called file one page at a time, proceed to next page using the spacebar

more file

Output the first 10 lines of file

head file

Display the first 20 lines of the file called file

head -20 file

Output the last 10 lines of file

tail file

Display the last 20 lines of the file called file

tail -20 file

Output the contents of file as it grows, starting with the last 10 lines

tail -f file

Compression

Create a tar named file.tar containing files

tar cf file.tar files

Extract the files from file.tar

tar xf file.tar

Create a tar with Gzip compression

tar czf file.tar.gz files

Extract a tar using Gzip

tar xzf file.tar.gz

Create a tar with Bzip2 compression

tar cjf file.tar.bz2

Extract a tar using Bzip2

tar xjf file.tar.bz2

Compresses file and renames it to file.gz

gzip file

Decompresses file.gz back to file

gzip -d file.gz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment