nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Find all directories under current directory and set their permission to 775
find -type d exec chmod 775 {} +
Sort standard input in alphabetical order
sort
Write output of "ls -lR /" to standard output and to "output.file"
ls -lR / | tee output.file
Show manual page of find utility
man find
Print each unique line that is duplicated in files "file1" and "file2" combined
sort file1 file2 | uniq -d
Find all files/directories with '.xml' extension that start with 'log4j' in their names under '/cygdrive/e/MyDocs/Downloads/work/OATS Domain related/' directory tree, search for files that contain the string 'CONSOLE' in their contents, then search for the string 'ASYNC' in the matched files and display the matched lines along with their filenames
find "/cygdrive/e/MyDocs/Downloads/work/OATS Domain related/" -iname "log4j*.xml" | xargs -I % grep -ilr "CONSOLE" "%" | xargs -I % grep -H "ASYNC" %
Print the most recently modified file
ls -1tr * | tail -1
Rename file "edited_blah.tmp" to "/etc/blah"
sudo mv edited_blah.tmp /etc/blah
display all the regular/normal files in the current folder that are not accessed in the last 10 minutes
find . -type f -amin +10
Search the file system for regular files whose names are shorter than 25 characters
find / -type f|egrep "/[^/]{0,24}$"
Make a playlist out of all the mp3 and ogg files in the home directory
find ~ -type f \ > mynewplaylist.m3u
recursively convert all symlinks under the current working folder to its regular file
find . -type l | while read f; do /bin/cp -rf --remove-destination -f $(find . -name $) "${f}";done;
Creates temporary folder and save path to that in a TMPDIR variable.
TMPDIR=$
Removes first and last parts of path $path and saves the result in 'finalName' variable.
finalName=$
Show the list of files that are not owned by user wnj or are not newer than file `ttt'
find / \! \( -newer ttt -user wnj \) -print
Find all files that are set user ID to root
find . -user root -perm -4000 -print
View the contents of "file.txt" with line numbers in the pager "less"
cat -n file.txt | less
Read a line from standard input with prompt "Enter your age:\n"
read -p $'Enter your age:\n'
display all the configuration files in "/etc" folder along with their last access and modified timestamps
find /etc -name "*.conf" -printf "%f accessed %AF %Ar, modified %TF %Tr\n"
Print your/dir if it's an empty directory
find your/dir -prune -empty -type d
Make directories to "/my/other/path/here/" as needed
mkdir -p /my/other/path/here/
start from current directory, skip the directory src/emacs and all files and directories under it, and print the names of the other files found
find . -wholename './src/emacs' -prune -o -print
Print the current directory
find -mindepth 0 -maxdepth 0
Create a symbolc link named "public_html" to "current/app/webroot" under the current working directory
ln -s `pwd`/current/app/webroot public_html
Print the given file name's extensions.
echo "$NAME" | cut -d'.' -f2-
Recursively changes group ownership of everything in 'files' to 'apache_user'.
chgrp -R apache_user files
display all files in the file system which are bigger than 50MB and having size "filename" in them
find / -size +50M -iname "filename"
Find all files/directories named 'foo' in the entire filesystem
find / -name foo
Recursively set all permissions under "/opt/lampp/htdocs" to 755
sudo chmod 755 -R /opt/lampp/htdocs
Find all *.rb (regular) files under current directory and count their line numbers
find . -name "*.rb" -type f -exec wc -l \{\} \;
Search for non-empty files
find . ! -size 0k
Display hostname.
uname -n
Add line numbers to each non-blank line in "file" starting with number 1000001
nl -v1000001 file
display the contents of all the files in the current folder which start with test ( case insensitive search )
find . -iname '*test*' -exec cat {} \;
Search for all files in the current directory recursively whose names contain "linkin park", ignoring the case
find . -iname "*linkin park*"
Create archive "backup1.tar" of all subdirectories of the current directory
find . -mindepth 1 -maxdepth 1 -type d | awk 'BEGIN {FS="./"}; {print $2}' | xargs -d '\n' tar czf backup1.tar
Find regular files whose names end in .JPG
find . -type f -name "*.JPG"
Find all foo.mp4 files in the current directory tree and print the pathnames of their parent directories
find . -name foo.mp4 | sed 's|/[^/]*$||'
Find all files/directories named 'document' in the entire filesystem
find / -name document -print
Find files that have a modification time of a day ago
find / -mtime 1
find all '*.c' files under $HOME directory which context contains sprintf
find $HOME -name '*.c' -print | xargs grep -l sprintf
display a long listing of all fles in current folder which have been modified in the last 60 minutes
find . -mmin -60 -ls
Print the physical current working directory
echo "`pwd -P`"
List all files/directories under current directory matching the posix-egrep type regex ".+\.$" in their names
find . -regextype posix-egrep -regex ".+\.$" -print0 | xargs -0 -n 1 ls
Rename the *.so files in the current directory tree prepending their names with "lib"
find . -name "*.so" -printf "mv '%h/%f' '%h/lib%f'\n" | bash
Remove all files that end with 'prefs copy' in their names under '/mnt/zip' directory tree
find /mnt/zip -name "*prefs copy" -print | xargs rm
Print the largest 20 files under current directory
find . -type f -printf '%k %p\n' |sort -n |tail -n 20
Show directory sizes in KB and sort to give the largest at the end
du -sk $(find . -type d) | sort -n -k 1
Find deb packages in the current directory recursively
find . -type f -and -iname "*.deb"
Search the files from the current directory tree for "foo"
find . -exec grep -l foo {} \;
Prints top-ten of most used utilities from history.
history | awk '{print $2}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -nr | head
Print entire virtual memory usage of the current user
ps -u $ --no-header -o vsz | dc -f - -e '[+z1<r]srz1<rp'
Prints total number of lines of all *.php files in a current folder and subfolders.
cat `find . -name "*.php"` | wc -l
Copy the entire directory tree under t1 to t2, do not create a containing t1 directory in t2.
cp -R t1/ t2
find all the files in the folder /opt which have been changed in the last 120 minutes
find /opt -cmin -120
List all regular files in the current directory tree
find . -type f -exec ls -l '{}' \;
Search everywhere for hidden file `.profile'
find / -name .profile
print difference in days between two dates
echo $(( ( $ - $ )/60/60/24 )) days
long list al the files in the current directory which have only read permission to the group
find . -perm 040 -type f -exec ls -l {} \;
Find all regular files that were modified more than 60 days ago under '/path-to-directory' directory tree, sort them according to timestamp and print the filenames preceded with the timestamps
find /path-to-directory -type f -mtime +60 -printf "%T@ %p\n" | sort
Compress files excluding *.Z files
find . \! -name "*.Z" -exec compress -f {} \;
Creates temporary file name and saves path to it in 'TMP_FILE' variable.
TMP_FILE="$(mktemp -t)"
Search the current directory tree for directories that can be opened by noone
find -type d ! -perm -111
list all .c or .sh regular files.
find . -type f \
Format the time string $timestamp according to the format string "%Y-%m-%d %H:%M:%S" and save the output to variable 'CDATE'
CDATE=$
Make a list of all files in the current directory tree, except *.png and *.class, and view it in the vim editor
find . | grep -E -v '\.png$|\.class$' | vim -
Print the paths of the directories from the paths expanded by the glob pattern /path/to/directory/*
find /path/to/directory/* -maxdepth 0 -type d
Force create a symbolic link named "$*" to the canonical absolute path of "$1"
ln -sf "$" "$*"
Find all regular files with '.txt' extension excluding 'README.txt' files under current directory tree
find . -type f -name "*.txt" ! -name README.txt -print
find all ".flac" files starting with "cmn-" and search for files having CJK characters using unicodes
find . -name 'cmn-*\.flac' -print | grep -P './cmn-[\x4e00-\x9fa5]\.flac'
display all files in the current folder expect text files
find . -name "*.txt" -prune -o -print
Continuously send "Y" to input of "command-that-asks-for-input"
yes Y | command-that-asks-for-input
Creates temporary file with file name formatted like /tmp/gnuplot_cmd_$.XXXXXX.gnuplot and saves path to it in a variable 'gnuplotscript'.
gnuplotscript=$(mktemp /tmp/gnuplot_cmd_$.XXXXXX.gnuplot)
Find all the files whose permissions are 777
find . -type f -perm 0777 -print
Find file `foo.bar' and delete it
find /home -name foo.bar -type f -exec rm -f "{}" ';'
Print either "one" or "two" randomly three times
yes $'one\ntwo' | head -10 | nl | sort -R | cut -f2- | head -3
removes last N lines from file.txt
head --lines=-N file.txt
Display last 100 lines of file-with-line-too-long.txt, waiting for user input after each page.
tail -1000 file-with-line-too-long.txt | more
Find recursively the latest modified file in the current directory
find . -type f | sed 's/.*/"&"/' | xargs ls -E | awk '{ print $6," ",$7 }' | sort | tail -1
Check whether "/full/path" is a mount point with no output and using the exit code
df /full/path | grep -q /full/path
Recursively change the ownership of all files in "/Users/xxx/Library/Developer/Xcode/Templates" to "xxx"
sudo chown -R xxx /Users/xxx/Library/Developer/Xcode/Templates
Remove all files that were older than 3 days
find . -type f -mtime +3 –exec rm –f {} \;
Counts total number of all '*.py' files beginning from root folder, and shows 'tqdm' progress bar.
find / -name '*.py' -exec cat \{} \; | tqdm --unit loc --unit_scale True | wc -l
Search for files/directories with the case insensitive pattern anaconda* in /var/log
find /var/log/ -iname anaconda*
Search for regular expression 'expr' in all .c and .h files from the current directory tree
find -name '*.[ch]' | xargs grep -E 'expr'
Find all files/directories in entire file system that have "write" bit set for either the owner, the group, or others
find / -perm /u+w,g+w,o+w
force create hard link between $GIT_DIR/../apresentacao/apresentacao.pdf and $GIT_DIR/../capa/apresentacao.pdf
ln -f $GIT_DIR/../apresentacao/apresentacao.pdf $GIT_DIR/../capa/apresentacao.pdf
Sets 'extglob' shell option.
shopt -s extglob
Copy local file "$1" to host "$2" into host directory "$3"
cat $1 | ssh $2 "mkdir $3;cat >> $3/$1"
List every directory under current directory with their child executable files
find . -type d -print -exec bash -c 'find {} -type f -depth 1 -perm +0111 | sort -r' \;
Print inode, permissions, size, and modification date of all files in the current directory tree as a list with an extra column prepended
tree -afispugD --inodes | awk '{FS="./"; ORS=""; printf}'
find all files in and under the current directory that have read, write and execute permissions set for all users.
find . -perm 777 -print
Search all files in the current directory tree, except *.html and *.svn*, for "SearchString"
find . ! -name '*.html' ! -name '*.svn*' -exec grep 'SearchString' {} /dev/null \;
Create an empty file with a carriage return character in its name.
touch $'Icon\r'
Find all files whose names end with "~" in the /home/peter directory tree, following symlinks, and delete them
find -L /home/peter -name *~ -exec rm '{}' \;
set alias "mkdir" for command ¨mkdir -p¨
alias mkdir=¨mkdir -p¨
display all the text files in the current folder
find -name “*.txt”
Find recursively regular files in the current directory tree
find . -type f -print
Read a line from standard input into variable "foobar" and suppress showing user input
read -s foobar
Find all files under Mainfolder directory and redirect the output to outputfle
find Mainfolder -type f > outputfile