nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Count the number of .java files in all folders rooted in the current folder
find . -name "*.java" | wc -l
Change directory to the directory containing file path "$1"
cd "$"
Globally sets the maximum number of lines to held in window history as 10000.
tmux set -g history-limit 10000
List directories in the current working directory and remove the trailing "/"
ls -1p | grep '/$' | sed 's/\/$//'
Find and uncompress all files in the current directory tree ending in ".csv.gz"
find . -name '*.csv.gz' -print0 | xargs -0 -n1 gzip -d
Find all SGID set files in the file system
find / -perm /g=s
find all the files in the entire file system which belong to the user "roger"
find / -user roger -print
Sort file1 and file2 then display differences between them.
diff < <
Print which files differ in "/tmp/dir1" and "/tmp/dir2" recursively
diff -qr /tmp/dir1/ /tmp/dir2/
Print file system disk space usage with sizes in powers of 1000
a=$
remove all text files from the current folder. Print0 is used to handle files whose names have only spaces or those files which have newlines in their names
find -name "*.txt" -print0 | xargs -0 rm
find all the files in the current folder whose name starts with 2 alphabets and ends with 2 digits.
find . — name "[a‑z][a‑z][0—9][0—9].txt" — print
Compress the file 'file' with 'bzip2' and append all output to the file 'logfile' and stdout
bzip2 file | tee -a logfile
search for the pattern "tgt/etc/file1" in the files tgt/etc/file2, tgt/etc/file3
find . -type f -name \* | grep tgt/etc/file1 tgt/etc/file2 tgt/etc/file3
Search the regular files of the current directory tree for string "stringYouWannaFind", ignoring the case
find ./ -type f -print -exec grep -n -i "stringYouWannaFind" {} \;
Count all directories under current directory
find . -type d -exec ls -dlrt {} \; | wc --lines
Find all * * regular files under current directory
find . -type f -name "* *"
Moves file '$2' to the folder where '$1' file is located.
mv "$2" "`dirname $1`"
Prints long recursive listing of all content of a root folder, saving output to 'output.file'.
ls -lR / | tee output.file
set alias "iTMSTransporter" for command '`xcode-select --print-path`/../Applications/Application\ Loader.app/Contents/MacOS/itms/bin/iTMSTransporter'
alias iTMSTransporter='`xcode-select --print-path`/../Applications/Application\ Loader.app/Contents/MacOS/itms/bin/iTMSTransporter'
Find all files on the system whose names are 'drush'
find / -name drush
List the files in the /etc directory tree containing text "old1.old2.co.com"
find /etc -type f -print | xargs grep -il old1\.old2\.co\.com
Search the /Path directory tree for files matching pattern "file_name*"
find /Path -name "file_name*"
extract the content of the file large.csv.gz and split it into pieces per 1000 lines named as xxxNNN
gzcat large.csv.gz | split -l 1000 - xxx
Print "a\nb\ncccccccccccc\nd" as two columns and neatly format into a table
echo -e "a\nb\ncccccccccccc\nd" | paste - - | column -t
To match only hidden dot directories
find /nas01/backups/home/user/ -type d -name ".*" -print0 -exec ls -lrt {} \;
List all directories of the $topdir directory tree that contain a Makefile and at least one .py file
find "$topdir" -name '*.py' -printf '%h\0' | xargs -0 -I {} find {} -mindepth 1 -maxdepth 1 -name Makefile -printf '%h\n' | sort -u
Prints long listing of a last modified file in a current folder.
find . -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" " | sed 's/.*/"&"/' | xargs ls -l
find all files in the file system which have been accessed in the last 24 hours
find / -atime 0
Print all lines from the last occurrence of the regex 'pattern' to the end of the file 'file'
tac file | sed '/pattern/q' | tac
create a tar.gz compress file with all the jpg files in the entire file system
find / -name *.jpg -type f -print | xargs tar -cvzf images.tar.gz
Recursively change the user and group of all files in "/var/lib/jenkins" to "root"
chown -R root:root /var/lib/jenkins
Print local files without descending non-local directories
find . ! -local -prune -o -print
Print second section of space-separated data coming from stdin.
cut -d\ -f 2
Copies all files like 'lib*.so' to '~/usr/gtest/lib/' directory.
cp lib*.so ~/usr/gtest/lib
Archive "/path/to/files" on host "remotemachine" authentifying as user "user" and compressing data during transmission, copy symlinks as symlinks.
rsync -avlzp user@remotemachine:/path/to/files /path/to/this/folder
set a crontab to create or update the timestamp of "washere1" in the current directory every minute.
echo "* * * * * touch $(pwd)/washere1" | crontab
Find all files in current directory and execute multiple commands for each file
find . -type f \
Set the host name to the contents of "/etc/hostname"
hostname $
find all files with the first letter “e” or “f” and last one x in /usr/bin directory:
find /usr/bin -name [ef]*x
Count the number of unique duplicate lines in "file1" and "file2" combined
sort file1 file2 | uniq -d | wc -l
verbosely create intermediate directoriy tmp as required and directory boostinst
mkdir -pv /tmp/boostinst
Search the current directory tree for regular files changed less than 1 day ago
find . -type f -ctime -1
Find all files under current directory and print only the filenames
find . -type f -printf "%f\n"
Finds IP address of system network interface, that belongs to 192.168.111 subnet.
ifconfig | grep 192.168.111 | awk '{print $2}'
Search the current directory tree for regular files whose names end in ".shtml" or ".css"
find -type f -regex ".*/.*\.\"
Find all executable files under current directory and show a few lines of output from the beginning
find . -perm /a=x | head
Find recursively all empty directories in the current directory
find . -type d -empty
Find all *.p[lm] files under /users/tom directory that matches the regex '->get(\|#hyphenate' in their contents
find /users/tom -name '*.p[lm]' -exec grep -l -- '->get(\|#hyphenate' {} +
Print variable "$module" in formatted rows
column -x <<< "$"
Find all files/directories under '/usr' directory tree that have been modified exactly 5 minutes ago
find /usr -mmin 5
Create an empty index.html in each directory under the current one, updating timestamps of already existing index.html files.
find . -type d -exec touch {}/index.html \;
display a long list of all the files that are bigger than 10KB in current folder and save the output to the file myLogTxt.text
find . -size +10k -type f -maxdepth 1 -exec ls -lh {} \; > myLogFile.txt
Get the total sizes of all files under current directory
find . -type f -printf '%p %s\n' | awk '{sum+=$NF}END{print sum}'
Print content of each file under the current directory followed by that file name
find . -type f -exec cat {} \; -print
Display a long listing of all files/directories that are bigger than 10MB under '/var/' directory tree
find /var/ -size +10M -ls
Remove junk files modified more than 31 days ago recursively
find /path/to/junk/files -type f -mtime +31 -print0 | xargs -0 -r rm -f
Lists the pids of all processes that have process '1782' as their parent.
pstree -p 1782 | sed 's/-/\n/g' | sed -n -e 's/.*(\([0-9]\+\)).*/\1/p'
Find all files in /var/www/html/zip/data/*/*/*/*/* that are older than 90 days and print their parent directory paths
find /var/www/html/zip/data/*/*/*/*/* -type f -mtime +90 | sed 's|/[^/]*$||'
create directory saxon_docs
mkdir saxon_docs
Find files/directories named 'aaa.txt' under current directory tree
find . -name aaa.txt
Output all lines from file1 except those present in file2, assuming both files are sorted.
diff --new-line-format="" --unchanged-line-format="" file1 file2
List all files/directories under current directory by replacing all spaces with commas
find . -ls | tr -s ' ' ,
find all the files in the home folder that are modified day before yesterday
find $HOME -mtime -2 -mtime +1
Print the last 10 lines of the file '/var/log/syslog'
tail /var/log/syslog
Print output of 'script -c "./a" /dev/null' to standard output and "output.txt"
script -c "./a" /dev/null | tee output.txt
List all files from the current directory tree that were modified less than 60 minutes ago, omitting "."
find . -mindepth 1 -mmin -60 | xargs -r ls -ld
Find directories under maximum 1 level down the directory $dir with 100 permission that are owned by the user $username
find $dir -maxdepth 1 -type d -user $username -perm -100
Removes all files but 5 newest ones from current folder.
ls -tp | grep -v '/$' | tail -n +6 | tr '\n' '\0' | xargs -0 rm --
Print each character of "abcdefg" on a line
echo "abcdefg" | fold -w1
Remount "rfs" filesystem "/dev/stl12" on "/system" with read and write permission
mount -o rw,remount -t rfs /dev/stl12 /system
Counts total lines in all *.php files.
find . -type f -name '*.php' -exec bash -c 'wc -l "$0"' {} \; | awk '{s+=$1} END {print s}'
display a long listing of all regular/normal files in current directory which have been changed in the last 7 days and save the output to new.files
find ./ -type f -ctime -7 -exec ls {} \; > new.files
Create a tar archive of all regular files modified in the last 24 hours
tar cvf - `find . -mtime -1 -type f -print` > $archive.tar
Find all files/directories named 'photo?.jpg' under current directory tree
find . -name photo\?.jpg
Print linux group names on multiple lines instead of single line output
groups | tr \ \\n
Search the current directory for *rc.conf files and grant "other" users read permission
find `pwd` -name "*rc.conf" -execdir /bin/chmod o+r {} \;
Finds binaries names in a list of running processes and prints containing folder of each binary.
ps aux | awk '{print $11}' | grep -x -e "/.*" | xargs dirname
Copy file linked to by "bar.pdf" to "bar.pdf"
cp --remove-destination `readlink bar.pdf` bar.pdf
Look for *.jpg files
find . -name “*.jpg”
Print the gcc version installed on "machine.example.com" using identity file "identity_file" and suppressing the known hosts check and warnings
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet -i identity_file machine.example.org gcc -dumpversion
Find all files/directories under current directory and rename them by replacing all blank spaces with _ in their paths
IFS=$'\n';for f in `find .`; do file=$; [ -e $f ] && [ ! -e $file ] && mv "$f" $file;done;unset IFS
Search for all directories named foo, FOO, or any other combination of uppercase and lowercase characters beneath the current directory.
find . -iname foo -type d
Login to "host" using identity file "id_rsa"
ssh -i id_rsa host
Find all regular files in the entire filesystem that belong to the group 'users'
find / -type f -group users
find the top 25 files in the current directory and its subdirectories
find . -type f -exec ls -al {} \; | sort -nr -k5 | head -n 25
Report file system containing /tmp disk usage in kilobytes.
df -k /tmp
Print the IP addresses for the current host name
hostname -I | awk '{print $1}'
Count the number of "X" characters in "infile"
tr -d -C X <infile | wc -c
display all the files in the file system which belong to the user with the id 1005
find / -uid 1005
display all the ".sh" files in the current folder
find -name *.sh
Get a sorted list of the longest line with line number for each file under current directory
find . -iname '*.page' -exec awk '{if(length > L) { LINE=NR;L = length}} END {print L"|"FILENAME":"LINE}' {} \; | sort
Set the host name to "myServersHostname"
hostname myServersHostname
Recursively rename all files under /your/target/path replacing 'special' with 'regular' - all file/diretory names may not include spaces, and directory names containing such files may not contain the word 'special' in their name.
find /your/target/path/ -type f -exec rename 's/special/regular/' '{}' \;
Change the permission to 0644 for all files under current directory
find . -type f -exec chmod 0644 {} +
Remove all files whose names begin with "heapdump" and write their names to "delete.txt"
find . -name heapdump* -exec rm '{}' \; -print >delete.txt
Calculate a list of duplicate md5 sum hashes for all the ".java" files in the current directory
md5sum *.java | awk '{print $1}' | sort | uniq -d
find all the files in the current folder which are modified after /bin/sh.
find . -newer /bin/sh
Compute the mean average of the word count of *.txt files smaller than 2000 words in the home directory
find ~/Journalism -name '*.txt' -print0 | xargs -0 wc -w | awk '$1 < 2000 {v += $1; c++} END {print v/c}'
Search for "Stock" in all *.java files from the current directory tree
find . -name "*.java" | xargs grep "Stock"