nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Search the current directory recursively for MOV files, following symlinks
find . -iname "*.mov" -follow
Print "operator: " followed by the full name of "${USER}"
printf "operator: `finger ${USER} | grep Name: | cut -f3 -d:` \n"
Recursively finds all '*.pdf' files and folders in a current folder and removes them without prompting.
find . -name "*.pdf" -print0 | xargs -0 rm -rf
Read standard input until a null character is found and save the result in variable "line"
read -r -d $'\0'
Numerically sort each line of standard input
sort -n
prints absolute file paths for files in current directory
find `pwd` -maxdepth 1
Change the owner of "process" to "root"
sudo chown root process
Run `fastqc' on all the fastqc files in the current directory tree
find . -name "*.fq" -exec cat '{}' ';' | fastqc /dev/stdin
Search the regular files of the current directory tree for string "foo"
find ./ -type f | xargs grep "foo"
Print unique lines in sorted file "a.txt" compared to sorted file "b.txt"
comm -23 a.txt b.txt
Archive "somedir/./foo/bar/baz.c" to "remote:/tmp/" preserving the relative path of "foo/bar/baz.c"
rsync -avR somedir/./foo/bar/baz.c remote:/tmp/
Recursively copy newer files in "sourcedir/" to "[email protected]:/dest/dir/" via ssh
rsync -auv -e ssh --progress sourcedir/ [email protected]:/dest/dir/
Find files whose data was modified within the given days of the month
find ./ -daystart -mtime -10 -and -mtime +1
Copy "./export" recursively to "/path/to/webroot" preserving permissions
rsync -pr ./export /path/to/webroot
force remove all the c files in the current folder
find . -name "*.c" | xargs rm -rf
Dump "input_file" as a 2 byte hexadecimal, character, and octal value and view the contents in "less"
od -xcb input_file_name | less
Sort and print each unique line in "myfile.txt"
cat myfile.txt| sort| uniq
Save "1 4 6 9 11 17 22" as a bash array "arr"
read -a arr <<< "1 4 6 9 11 17 22"
List the current directory recursively ignoring the "dir1" subdirectory
find . -path ./dir1\* -prune -o -print
Print the current working directory with resolved symbolic links
pwd -P
display a list of all the files in the home folder which have been modified today
find ~ -type f -mtime 0 -ls
Find the largest original ".gz" file in the current directory tree
find . -name '*.gz' -print | xargs gzip -l | awk '{ print $2, $4 ;}' | grep -v '$' | sort -n | tail -1
display all the file in the folder /home/david/ which start with the word "index" ( case insensitive search)
find /home/david -iname 'index*'
Check if your/dir is empty or not
[ $ = your/dir ]
Pick up a list of variable:value pairs from msgs.config and add them to the current shell or script's environment.
source <( sed 's/:\(.*\)/="\1"/' msgs.config )
Make directories "3/foo", "3/bar", and "3/baz"
mkdir 3/foo 3/bar 3/baz
Recursively finds strings with"text string to search” in any file within the 'directory-path', following symlinks, and prints found strings with file names.
grep -r -H "text string to search” directory-path
Prints week day of a 31 day in a current month.
cal | awk -v date=31 'NR == 2 { split } NR > 2 { for if { print header[NR == 3 ? i + 7 - NF : i]; exit } }'
bind "\C-i" to "complete" function
bind '"\C-i":complete'
Change permissions to 644 of multiple files with permissions 755
find . -perm 755 -exec chmod 644 {} \;
Find all files/directories under current directory and set their permission to 775
find . -type f -exec chmod 775 {} \;
Wrap each line in "file" to fit in 80 characters and count the number of lines
fold file | wc -l
Search the directories that match pattern '/path/to/directory/folder{?,[1-4]?,50}' for .txt files
find /path/to/directory/folder{?,[1-4]?,50} -name '*.txt'
Make hidden directory ".hiddendir"
mkdir .hiddendir
Search for files/directories with the case insensitive pattern anaconda.* in var/log directory and create an archive of the last block of files sent to xargs
find var/log/ -iname anaconda.* | xargs tar -cvf file1.tar
Find all files under ./lib/app and sort them
find ./lib/app -type f | sort
Delete all files named "filename" in the current directory tree, except those with paths ending in "/myfolder/filename"
find . -name "filename" -and -not -path "*/myfolder/filename" -delete
Delete all contents form the files that contain the case insensitive regex 'stringtofind' in maximum 1 level down the / directory excluding other partitions
find / -maxdepth 1 -xdev -type f -exec grep -li "stringtofind" {} + | parallel sed "'/./d'" '{}'
Prints a random number between 2000 and 65000
seq 2000 65000 | sort -R | head -n 1
find all the files in the current folder which have the word cache in them and do not search in the sub directories of the folder.
find . -name 'cache*' -depth -exec rm {} \;
Replace all matches with the regex expanded by $P_FROM with the text expanded by $P_TO in all regular files under current directory not going into subdirectories and modify the files in-place
find . -type f -maxdepth 1 -exec sed -i "s/$P_FROM/$P_TO/g" {} \;
Save the list of files modified within a fortnight ago to `deploy.txt'
find . -type f -mtime -14 > deploy.txt
Mount a read only ntfs filesystem
mount -t ntfs
replace the word apple with orange in all the files in the current folder
find ./ -exec sed -i 's/apple/orange/g' {} \;
Silently read standard input until the escape key is pressed ignoring backslash escapes and using the prompt $'Press escape to continue...\n'
read -rsp $'Press escape to continue...\n' -d $'\e'
Search the current directory recursively for regular files last changed more than 2 days ago
find . type -f -ctime +2
Read a single character from standard input into variable "key" without backslash escapes and using an interactive shell with the prompt $'Are you sure : ' and default value $'Y'
read -rp $'Are you sure : ' -ei $'Y' key
Execute "some_script" on all files in the current directory tree
find -exec some_script {} \;
move all files in the current folder another folder and do not move the files in the sub folder
find . -name "*" -maxdepth 1 -exec mv -t /home/foo2/bulk2 {} +
Find all files and directories with permissions 664
find . -perm 664
find all the files in the entire file system which have been modified in the last 48 hours
find / -mtime -2 -print
Finds all files with names like "*.rm" in a current folder, launches ffmpeg conversion for each one, and deletes source file after.
find . -type f -name "*.rm" -exec ffmpeg -i {} -sameq {}.mp3 \; -exec rm {} \;
Counts all files in a current folder and subfolders.
find . -type f | wc -l
Count the number of equal lines in "file1.txt" and "file2.txt"
comm -12 <(sort file1.txt) <(sort file2.txt) | wc -l
Create a bzip2 archive `dir_txt.tar.bz2' of all .txt files in the dir/ directory tree
find dir/ -name '*.txt' | tar -c --files-from=- | bzip2 > dir_txt.tar.bz2
Print every file's type, name, and inode
find -printf "%y %i %prn"
search for the word text in all the python files in the current folder
find . -iname '*py' -exec grep "text" {} \;
display all the empty files in the entire file system
find / -size 0 -print
List all environment variables whose name or value contains current user's login name.
env | sed -n /"$USERNAME"/p
Print mount point of the file system containing $path.
df -P "/tmp" | awk 'BEGIN {FS="[ ]*[0-9]+%?[ ]+"}; NR==2 {print $NF}'
Find all files/directories under current directory tree that belong to user 'john'
find . -user john
Decompress "path/to/test/file.gz" to standard output and save all lines matching "my regex" to files with a 1000000 line limit
gzip -dc path/to/test/file.gz | grep -P --regexp='my regex' | split -l1000000
Split "domains.xml" into files of at most 50000 lines each with a numeric suffix of length 4 and prefix of "domains_"
split -a 4 -d -l 50000 domains.xml domains_
list all .c or .sh regular files.
find . -type f \( -name "*.c" -o -name "*.sh" \)
create directory aaa/bbb
mkdir aaa/bbb
search for all the files having spaces in the current folder and save the output to the variable founddata
founddata=`find . -name "filename including space" -print0`
find all the backup files in the current folder and delete them after user confirmation
find . -type f -name "*.bak" -exec rm -i {} \;
Find all files in the current directory tree whose names end with the suffix ".keep.$1", where $1 is the first command line argument, and remove that suffix
find . -type f -name "*.keep.$1" -print0 | while IFS= read -r -d '' f; do mv -- "$f" "${f%.keep.$1}"; done
Show the date in default format for tomorrow + 2 days + 10 minutes
date -d tomorrow+2days-10minutes
Search the /home/bozo/projects directory tree for files modified within the last 24 hours
find /home/bozo/projects -mtime 1
Search the current directory for PHP files
find . -type f -name "*.php"
displays all the files in the current folder
find .
Use the last 100 lines of "file1" as input to "wc -l" and monitor the pipeline with the "bar" command
tail -n 100 file1 | bar | wc -l
display all the ".sh" files in the current folder
find -name *.sh
display all the files in the current folder for the files which have been accessed in the last 24 hours
find . -type f -atime -1
Compare "file1" and "file2" line by line with 3 lines of unified context
diff -u file1 file2
find all files in the current folder which have been modified after /etc/passwd
find -newer /etc/passwd
display all the pdf files in a folder which start with a specific word along with their timestamp in sorted order of time and save output to a in remote server
find "/path/to/pdfs/" -type f -name "$1*.pdf" -printf "%TY/%Tm/%Td %TH:%TM %p\n" | sort -n -k1.1,1.2 -k1.3,1.4 -k1.6,1.7 -k1.9,1.10 -k2.1,2.2 -k2.4,2.5 -k3 > remoteuser@remoteserver:/u/tmp/CustTmp/zzz_pdfs.txt
Find all files larger than 20000k and print their names and sizes
find / -type f -size +20000k -exec ls -lh {} \; | awk '{ print $8 ": " $5 }'
Extract any line in "file1" or "file2" which does not appear in the other
comm -3 < <
Make directory "/path/to/destination"
mkdir /path/to/destination
Make directories to "directory{1..3}/subdirectory{1..3}/subsubdirectory{1..2}" as needed
mkdir -p directory{1..3}/subdirectory{1..3}/subsubdirectory{1..2}
search for all the files in the folder /home which have sticky bit set and have the permissions 553
find /home -perm 1553
display all the regular/normal files in a folder
find ./subdirectory/ -type f
Delete all *.zip files under current directory that are older than 2 days
find . -name "*.zip" -mtime +2 -print0 | xargs -0 -I {} rm {}
find all files in the current directory excluding those that end with .js or have the words .min or console in their name
find . -type f \( -name "*.js" ! -name "*-min*" ! -name "*console*" \)
Count md5sum of all '*.py' files in a current folder with subfolders.
find /path/to/dir/ -type f -name "*.py" -exec md5sum {} + | awk '{print $1}' | sort | md5sum
search for all the files in current folder and display all the file names separated by space
find . | awk '{printf "%s ", $0}'
Move all files including hidden files and excluding ".." in "/path/subfolder/" to "/path/"
mv /source/path/{.[!.],}* /destination/path
Save the UTC date represented by time string $sting2 as the seconds since epoch to variable 'FinalDate'
FinalDate=$
change the permissions of all the directories in the current folder
find . -type d | xargs chmod 2775
To descend at most one levels of directories below the command line arguments pass the -maxdepth 1 option. This will avoid deleting nested directories:
find . -maxdepth 1 -type d -iname ".[^.]*" -print0 | xargs -I {} -0 rm -rvf "{}"
Make directory "certs"
mkdir certs/
Find all executable files
find / -perm /a=x
Copy all *.data files under jcho directory to files whose names are constructed by appending the parent directory names at the beginning of their names
find jcho -name '*.data' | while read -r f; do cp "$f" "$(echo "$f" | sed 's~\]*\)/\([^]*\)$~\1_\2~')"; done
find all readable files
find / -readable
Force delete all files in the temp folder which have not been accesses in the last 240 hours
find /tmp/* -atime +10 -exec rm -f {} \;
Read a line from standard input into variable "PASSWORD"
read PASSWORD
Archive showing progress "sourcefolder" to "/destinationfolder" excluding "thefoldertoexclude"
rsync -av --progress sourcefolder /destinationfolder --exclude thefoldertoexclude
display all directories in a folder
find /etc -type d -print