nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Delete all *.zip files under current directory that are older than 2 days
find . -name "*.zip" -mtime +2 orint0 | xargs -0 rm
Page through the contents of yourFile, adding a $ at the end of each line.
cat -e yourFile | less
prints the maven project version
mvn help:evaluate -Dexpression=project.version | tail -8 | head -1
find files in /usr directory which are modified after February 1 of the current year
find /usr -newermt "Feb 1"
Login to a bash shell on localhost via ssh and print the bash version
echo 'echo "Bash version: ${BASH_VERSION}"' | ssh -q localhost bash
create a compressed archive "filename.tar.gz" with verbose output
tar -cvzf filename.tar.gz folder
Check if the file "somelink" links to exists
ls `readlink somelink`
Display the biggest file sizes only
find -type f -exec du -Sh {} + | sort -rh | head -n 5
Print the names and sizes of regular files residing in the current directory tree
find $/* -type f -exec stat -c "f%15s %n" {} +
Remove what follows the forth occurrence of the character ":" in any field which contains it
sed -r 's/((:[^: \t]*){3}):[^ \t]*/\1/g' file | column -t
Find empty files and directories
find . -empty
Gets IP address of first listed active network interface in system.
ifconfig | grep 'inet addr:' | grep -v '127.0.0.1' | awk -F: '{print $2}' | awk '{print $1}' | head -1
Search for "mpirun" in all processes owned by the current user
pgrep -u `whoami` mpirun
Save count of lines from file $file matching with pattern $filter and not matching with pattern $nfilter in variable 'totalLineCnt'
totalLineCnt=$(cat "$file" | grep "$filter" | grep -v "$nfilter" | wc -l | grep -o '^[0-9]\+');
Display infinite scroll of random ASCII art
yes 'c=(╱ ╲);printf ${c[RANDOM%2]}'|bash
Create a new window in an existing screen session and run a script
screen -S demo -p 1 -X screen '/home/aa/scripts/outputs.sh'
Unzip and extract "userAgent=[^=]*'" from "input.gz"
zcat input.gz | grep -o 'userAgent=[^=]*' | sed 's/ [^ ]*$//'
Display current system's kernel name, kernel release and version, and machine architecture
uname -srvm
Unzip "daily_backup.sql.gz" and search for lines matching "'x'|/x/"
zcat daily_backup.sql.gz| grep -E "'x'|/x/"
find all files in the current folder which have been modified in the last 24 hours
find . -mtime -1 -print
Calculate the sum of all the numbers from 1 to 10
seq 10 | tr '[\n]' '+' | sed -e 's/+/ + /g' -e's/ + $/\n/' | xargs expr
Prints full path to files in a current folder.
ls -d -1 $PWD/**
Search "file1" for lines matching regex patterns listed in "file2" and list the unique results (sorted alphabetically)
grep -f file2 file1 | sort | uniq
returns a list of files modification newer than poop
find . -mnewer poop
display all hidden files in the current folder
find . -type f -name ".*"
find all the empty directories in the current folder and all its sub directories too
find . -depth -empty -type d
Make directories "./es/es_MX.utf8/LC_MESSAGES" as needed and do not error if it exists
mkdir --parents ./es_MX.utf8/LC_MESSAGES
Find the string 'joomla' case insensitively in all the php and html files under current directory tree and display the matched lines along with the file names and line numbers
find . \( -name "*.php" -o -name "*.html" \) -print0 | xargs -0 grep -Hin "joomla"
Print the last line of "$file1" to the console and append to "$file2"
tail -1 $file1 | tee -a $file2
Find directories in /home/vmail that match pathname "*/*/Maildir/.LearnAsSpam/cur", and move them to folder .Junk/cur
find /home/vmail/ -type d -path "*/*/Maildir/.LearnAsSpam/cur" -exec sh -c '' ';'
search for the word "nameserver" in all the configuration files of the /etc folder
find /etc/ -type f -name "*.conf" -print0 | xargs -I {} -0 grep "nameserver" "{}"
Find all files/directories under current directory and sort them
find | sort
Find all *.c files under /home
find /home -name "*.c"
recursively change owner of the directory /usr/local/lib to the current user
sudo chown -R `whoami` /usr/local/lib
Find regular files with permissions less than 111
find -perm -111 -type f
Find all the SGID bit files under current directory whose permissions set to 644 and show a few lines of output from the beginning
find . -perm 0644 | head
Convert symlink to regular file
find . -type l | while read f; do /bin/cp -rf --remove-destination -f $(find . -name $) "${f}";done;
Find all files/directories in entire file system that are exactly 50 bytes
find / -size 50c
Find all files in the `sourceDir' directory
find sourceDir -mindepth 1 -maxdepth 1
Find files/directories under current directory that matches './projects/insanewebproject' in their paths and show the first one
find -ipath './projects/insanewebproject'| head -n1
display all the files in the current directory excluding those that are in the 'secret' directory
find . -name 'secret' -prune -o -print
Find files with SGID (2000) and SUID(4000) permssions set in the file system
find / \( -perm -2000 -o -perm -4000 \) -ls
search for all the files in current folder which start with "file2015-0" and move them to another folder
find . -name "file2015-0*" -exec mv {} .. \;
Check if the directory tree whose name is given as variable $somedir contains no regular files
find "$somedir" -type f -exec echo Found unexpected file {} \;
List current user's crontab.
crontab -l
Unsets GIT_DIR variable.
unset GIT_DIR
Find all directories under $1/.hg and set their SGID bit
find $1/.hg -type d -exec chmod g+s {} \;
Find all files/directories under current directory tree that are newer than backup.tar.gz by modification time
find . -newer backup.tar.gz
Make 3 directories named "$HOME/Labs/lab4a/folder" followed by a 3 width zero padded number from 1 to 3
mkdir $(seq -f "$HOME/Labs/lab4a/folder%03g" 3)
Copy the file foo.sh into /tmp of the docker container
tar -c foo.sh | docker exec -i theDockerContainer /bin/tar -C /tmp -x
Go to directory /cygdrive/c/Program Files (x86) using backslashes to escape special characters
cd /cygdrive/c/Program\ Files\ \(x86\)
Change the ownership of "/etc/udev/rules.d/51-android.rules" to "root"
sudo chown root. /etc/udev/rules.d/51-android.rules
excute script makeallsizes with all '*.jpg' file under originals directory.
find originals -name '*.jpg' | xargs -1 makeallsizes
Archive "_vimrc" to "~/.vimrc" suppressing non-error messages and compressing data during transmission
rsync -aqz _vimrc ~/.vimrc
List all variables (names and values) whose name or value contains X.
env | grep ".*X.*"
Find directory "your/dir" if it is empty
find your/dir -prune -empty
Find all Name* files under ../../$name-module and rename them by replacing 'Name' with $Name in their names
find ../../$name-module -print0 -name 'Name*' -type f | xargs -0 rename "s/Name/$Name/"
Print the input "hello world" to the console followed by a swap of the first two awk fields
echo hello world | tee /dev/tty | awk '{print $2, $1}'
remove all the core files in the home folder
find /home -name core -exec rm {} \;
Find files ending in "f"
find . -path '*f'
Calculate the md5 sum of all *.py files in the current directory
cat *.py | md5sum
Recursively change the ownership of all directories in the current directory excluding "foo" to "Camsoft"
ls -d * | grep -v foo | xargs -d "\n" chown -R Camsoft
Display inputfile all on one line
awk '{printf "%s ", $0} END {printf "\n"}' inputfile
Delete all regular files under current directory
find . -type f -print0 | xargs -0 /bin/rm
find all the "jpg" file in a folder.
find /win/C -iname *JPG
Set permissions for all direcotries under /var/www to 755
find /var/www -type d -print0 | xargs -0 chmod 755
recursively change owner and group of the directory and all files into it to user "user" and group "www-data"
chown -R user:www-data yourprojectfoldername
Move all files from the `sourceDir' directory tree to the `destDir' directory
find sourceDir -mindepth 1 -exec mv "{}" --target-directory=destDir \;
Find all directories under maximum 1 level down the current directory and set their permission to 700
find . -mindepth 1 -type d | xargs chmod 700
delete all the files in the current folder which end with ".bak" or ".backup" and which have not been accessed in the last 30 days
find . ( -name '*.bak' -o -name *.backup ) -type f -atime +30 -exec rm '{}' ;
search for all the ".c" files in the folder "/home/david" which have been modified in the last 10 minutes
find /home/david -mmin -10 -name '*.c'
display all files in the current folder expect text files
find . -name "*.txt" -prune -o -print
Find all files under /home/mywebsite/public_html/sites/all/modules and set their permission to 640
find /home/mywebsite/public_html/sites/all/modules -type f -exec chmod 640 {} +
Find files that are orphaned
find -nouser
Count total number of lines in all files below current directory.
find . -type f -exec wc -l {} \; | awk '{ SUM += $0} END { print SUM }'
start 2 sleep processes in the background
sleep 100 | sleep 200 &
Counts lines in each of *.php files in a current folder and subfolders ignoring 'tests' folder and prints total count as well.
find . -name tests -prune -o -type f -name '*.php' | xargs wc -l
find all the files in the folder ./machbook and change the owner of them to the user with id "184"
find ./machbook -exec chown 184 {} \;
Display the contents of "sample_0001.gz" with "lk=1&" removed
zcat sample_0001.gz | sed -e 's/lk=1&//g'
Find all files/directories under /proc and run ls command on each.
find /proc -exec ls '{}' \;
Synchronize "/home/user1/" to "wobgalaxy02:/home/user1/" including hidden files
rsync -av /home/user1/ wobgalaxy02:/home/user1/
List all available commands in Mac OS
echo $PATH | tr ':' '\n' | xargs -I {} find {} -maxdepth 1 -type f -perm '++x'
list PID of a group leader
jobs -lp
Write output and error of "bash myscript.sh" to standard output and to "output.log"
bash myscript.sh 2>&1 | tee output.log
Write the standard output and error of "someCommand" to the console and append it to "someFile"
someCommand 2>&1 | tee -a someFile
Search for "largecalculation" in all processes owned by the current user
ps -u `whoami` | grep largecalculation
find all regular/normal files which have cpp folder in their path
find . -type f -path "*/cpp/*"
Run 'join' with the number-sorted output of file1 and file2, without modifying file1 or file2: for each line with a common first field in file1 and file2, output the common field followed by the extra fields in both files.
join < <
find all jpg files in the folder which are in the path "/201111/" and sort them based on name
find */201111/* -name "*.jpg" | sort -t '_' -nk2
Automatically spell check file "text.txt" using "aspell" command
yes 1 | script -c 'aspell check text.txt' /dev/null
find all the regular files in the current folder which start with a "some text"
find . -type f -name '*some text*'
display all the files in the current folder which do not belong to any group
find . -nogroup
Find files and directories modified in last 7 days
find . -mtime -7
Prints last modified file in a current folder.
find . -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" "
Find out all *.sh owned by user vivek
find / -user vivek -name "*.sh"
Replace the spaces after line number in the output of history with ".."
history | sed 's/^\( *[0-9]*\) */\1../'
List all regular files from the current directory tree that were modified less than 60 minutes ago
find . -mmin -60 -type f -exec ls -l {} \;
display all the files in current folder which are bigger than 10KB
find . -size +10k
display all the log files in the folder /var/log, print0 is used to handle files with only spaces in their names or which have newlines in their names
find /var/log -name "*.log" -print0
find all raw images in the current folder and pass them one at a time to the xargs command and enable parallel processing of the files
find . -type f -iname '*.CR2' -print0 | xargs -0 -n 1 -P 8 -I {}