nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Count total number of lines in all *txt files in current directory
wc -l `find . -type f -name '*.txt' `
search in the current folder for all the regular/normal file with the name "test"
find . -type f -name test
Search for "pattern" in all the .c files in the current directory tree
find . -name "*.c" | xargs grep pattern
Find files with name `aaa.txt' under the current directory
find . -name aaa.txt
Unzip every ".gz" file in the current directory tree
find . -name "*.gz" | xargs gunzip
Make directories to "/tmp/test/blah/oops/something" as needed
mkdir -p /tmp/test/blah/oops/something
Search the current directory tree for regular files lacking read permissions for user, group, or others
find . -type f ! -perm -444
List *.pl directories in the current directory tree
find . -name "*.pl" -exec ls -ld {} \;
Search for hidden files non-recursively
find . -name '.?*' -prune
List all files/directories under current directory
find .
Delete all .svn files/directories under current directory
find . -name .svn -delete
Calculate the md5 sum of every ".py" file in directory tree "/path"
find /path -type f -name "*.py" -exec md5sum "{}" +;
Search for 'stuff' in all *,txt files under current directory
find . -name "*.txt" -print0 | xargs -0 egrep 'stuff'
Remove all files in the ~/backups/mydatabasename directory recursively that were last modified more than 30 days ago
find ~/backups/mydatabasename/* -mtime +30 -exec rm {} \;
Change the encoding of all *.java files in a directory and subdirectories from cp1252 to utf-8
find . -type f -name '*.java' -exec sh -c 'iconv -f cp1252 -t utf-8 "$1" > converted && mv converted "$1"' -- {} \;
find all the files in the file system which belong to the user "pat" and with the name "dateiname"
find / -user pat -iname "Dateiname"
Find "file.xml" under the current directory and change directory to its parent
cd `find . -name file.xml -exec dirname {} \;`
List all regular files in the current directory tree
find . -type f | xargs ls -l
Delete all regular files that have not been modified in the last 31 days under '/path/to/junk/files' directory tree
find /path/to/junk/files -type f -mtime +31 -exec rm -f {} \;
Find all files/directories under '/var/tmp' directory tree that belong to a user with user id 1000
find /var/tmp -uid 1000
find files in /usr directory which are modified after February 1 of the current year
find /usr -newermt "Feb 1"
Recursively set all permissions under "/directory" to 755
chmod -R 755 /directory
Prints date of first Tuesday in January, 2015
cal 01 2015 | sed -n '1,2b;/^.\{6\} \{0,1\}\ .*/ {s//0\1/;s/.*\$/\1/p;q;}'
Login in 'whatever.com' as user 'whoever' with X11 forwarding to enable GUI programs on remote to be run
create directory TestProject
mkdir TestProject
Delete current cron job list, and use those in yourFile.text
crontab yourFile.text
Find the top 25 files according to their size in the current directory and its subdirectories
find . -type f -exec ls -al {} \; | sort -nr -k5 | head -n 25
Rename uppercase file or folder name $1 to lower case name
mv $1 `echo $1 | tr '[:upper:]' '[:lower:]'`
search for all non empty regular/normal files in the current folder and empty them ie., delete the content not the file
find . -type f -maxdepth 1 -not -empty -print0 | xargs -0i cp /dev/null {}
Search the /usr/local/doc directory tree for .texi files
find /usr/local/doc -name '*.texi'
Find files/directories with inode number '212042' under '/var' directory tree without traversing other devices/partitions
find -x /var -inum 212042
Alias "cd $" as "cd-"
alias cd-='cd $'
Print the list of the subdirectories of the current directory
find . -mindepth 1 -maxdepth 1 -type d -printf "%P\n"
Rename all .jpg files to .jpeg under the current directory and below
find | rename 's/\.jpg$/.jpeg/'
Prints folder where current script is located
echo "dirname: `dirname "$0"`"
Find every file under the directory /usr ending in ".stat".
find /usr -name *stat
Print the list of 1st level subdirectories in /fss/fin
find /fss/fin -d 1 -type d -name "*" -print
List all environment variables whose name either equals HOME or PATH, or starts with GO
env | grep '^\'
display all the text files in current folder
find . -name "*.txt" -printf "%f\n"
find all js files under the build direcotry except build/external directory.
find build -not \( -path build/external -prune \) -name \*.js
Recursively from current folder searches only files that names match ".*xxx" pattern, ignores binary files and prints file name before every string that contains "my Text to grep".
grep --include="*.xxx" -nRHI "my Text to grep" *
Make directory "destdir"
mkdir destdir
List the full path of each directory under the current working directory
tree -dfi "$(pwd)"
Archive the directory structure under backup directory into directory-structure.tar
find backup/ -type d | xargs tar cf directory-structure.tar --no-recursion
Send SIGKILL signal to processes ID 18581, 18582, and 18583, killing them instantly.
kill -9 18581 18582 18583
Send SIGTERM signal to entire session of processes containing process whose ID is 21709.
kill $(ps -o pid= -s $)
Find all files/directories with 644 permission in entire file system
find / -perm 644
Run /bin/true with 1 to 99999 as arguments
/bin/sh -c "/bin/true $"
Remove trailing white spaces from all files under current directory ignoring .git and .svn directories
find . -not \ -type f -exec sed -i "s/[[:space:]]*$//g" "{}" \;
Calculate the sum of the 7th column of "ipcs -mb"
ipcs -mb | awk 'NR > 3 { print $7 }' | paste -sd+ | bc
Find files matching pattern $2 in the $1 directory recursively and search them for text $3, where $1, $2, $3 are the command line arguments to the Bash script
find $1 -path /proc -prune -o -name "$2" -print -exec grep -Hn "$3" {} \;
Print only lines from 'file1.txt' that not present in 'file2.txt' and beginning with 'Q'
cat file1.txt | grep -Fvf file2.txt | grep '^Q'
display all the files in current folder which have been changed in the last 24 hours
find . -ctime -1 -print
Print shared lines in "number.txt.gz" and "xxx.txt.gz"
zcat number.txt.gz | { zcat xxx.txt.gz | comm -12 /dev/fd/3 - ; } 3<&0
find ".flac" files in current folder using regular expressions
find ./ -regex "./cmn-.\.flac"
Enables shell option 'direxpand'.
shopt -s direxpand
Prints full path to files with dot in name in a current folder.
ls -d -1 $PWD/*.*
Print sed commands that would replace all occurrences of 'previousword' with 'newword' in all regular files with '.cpp' extension under '/myprojects' directory tree
find /myprojects -type f -name '*.cpp' -print0 | xargs -0 echo sed -i 's/previousword/newword/g'
Search the current directory recursively for regular files with extensions sdw, sdc, sdd and save the search result as "list_1"
find . -type f | egrep '$' > list_1
Replace all spaces (' ') with comma (',') in ${TO_IGNORE[@]}, append with '--ignore ' and save the resultant string to variable 'ARGS'
ARGS="--ignore `echo ${TO_IGNORE[@]} | tr ' ' ','`"
display all scala files in the directory "src/main"
find . -type f -regex ".*src/main.*\.scala$"
Search in current directory downwards all files whose size is 10 bytes ( Characters ) .
find . -size 10c -print
Case-insensitive search for "error" in file report.txt, display one page at a time, waiting for user interaction between each.
cat report.txt | grep -i error | more
Find all files named "something" in the current folder and below and run them through the ls -l command in a one batch.
find . -name something | xargs -0 ls
Display the file type description of /bin/bash, ie. symbolic link, ELF executable, etc.
$ file /bin/bash
Print fourth column of data from text file text.txt where columns separated by one or more whitespaces.
cat text.txt | tr -s ' ' | cut -d ' ' -f4
Find all directories under current directory and change their permission to 644
find -type d -print0|xargs -0 chmod 644
Find all files/directories with '.log' extension whose names start with 'app-', have been modified in the last 5 minutes and show the first one found
find /var/log/crashes -name app-\*\.log -mmin -5 -print | head -n 1
Delete all .bam files in the current directory tree
find . -name "*.bam" | xargs rm
Find the directories whose pathnames contain "New Parts" at level 3 of the current directory tree and create symlinks to them in /cygdrive/c/Views
find -mindepth 3 -maxdepth 3 -type d | grep "New Parts" | tr '\012' '\000' | xargs -0 ln -s -t /cygdrive/c/Views
Find all files in ~/clang+llvm-3.3/bin/ and print 'basename /file/path' for each file
find ~/clang+llvm-3.3/bin/ -type f -exec echo basename {} \;
Change every directory under "/var/www/html/" to have permissions 775
sudo find /var/www/html/ -type d -exec chmod 775 {} \;
display a long listing of all the directories in the current folder
find . -type d -exec ls -algd {} \;
Find all files under $source_dir that match the regex .*\.\(avi\|wmv\|flv\|mp4\) in their paths and print them with null character as the delimiter
find "$source_dir" -type f -regex ".*\.\(avi\|wmv\|flv\|mp4\)" -print0
find files in the home folder which have been modified in the last day. ( -daystart measures times from the beginning of today rather than from 24 hours ago.)
find ~/ -daystart -type f -mtime 1
Find all 0644 permission files/directories under current directory tree and show only the first 10 of them
find . -perm 0644 | head
Find *log files/directories within a maximum of 3 levels of directories
find / -maxdepth 3 -name "*log"
Create a symbolic link named "foo" to "/var/cache/apt/archives/bash_4.3-14ubuntu1_amd64.deb"
ln -s /var/cache/apt/archives/bash_4.3-14ubuntu1_amd64.deb foo
Print the current shell
ps | tail -n 4 | sed -E '2,$d;s/.* (.*)/\1/'
find all the directories in current folder which start with test
find . -type d -name "test*"
Removes all files like '*.bak' in a current folder, and prints messages about what is being done.
rm -v *.bak
find all the files ending with "clj" in the current folder and search for a pattern
find . -name *.clj | xargs grep -r resources
List and sort all leaf directories under current directory
find . -type d | sort | awk '$0 !~ last "/" {print last} {last=$0} END {print last}'
List all files and directories in long list format with a time style of "long-iso" and sort from oldest modifed to newest modified
ls -l --time-style=long-iso | sort -k6
Replace all newlines from standard input except the last with spaces
sed 'x;G;1!h;s/\n/ /g;$!d'
Rename "original.filename" to "new.original.filename"
mv {,new.}original.filename
Finds and deletes all empty folders .
find ./ -type d -exec rmdir --ignore-fail-on-non-empty {} 2>/dev/null \;
List all .jpg files in the home directory tree
find . -name "*.jpg" -exec ls {} \;
Print the basename from a colon separated path 'a:b:c:d:e'
basename $(echo "a:b:c:d:e" | tr ':' '/')
Locate all passwd files on the system
find / -name passwd
Find all files and directories in the current directory tree with "linkin park" in their names and copy them to /Users/tommye/Desktop/LP
find . -iname "*linkin park*" -exec cp -r {} /Users/tommye/Desktop/LP \;
Find all files in /home/user/ that were created or changed 10 minutes ago
find /home/user/ -cmin 10 -print
removes the 4th-from to 6th-from last lines in file
tac filename | sed 4,6d | tac
Print the path names of all .png files in the /home/kibab directory tree
find /home/kibab -name '*.png' -exec echo '{}' ';'
get all the files that have been modified within the last 30 days
find . -mtime -30 -print
Find all files and directories with permissions 664
find . -perm 664
Find files/directories named 'foo' in the current partition of the root filesystem
find -x / -name foo
find all the files ending with "mkv" in current folder
find -name "*.mkv"
change the permissions of all the normal files in a directory
find /path/to/dir/ -type f -print0 | xargs -0 chmod 644
Copy file "exist" from directory "/file/that" to a new file named "file" in "/location/for/new"
cp /file/that/exists /location/for/new/file