nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Change the owner of "destination_dir" to "user"
chown user destination_dir
Lists long format information about file '/bin/echo'.
ls -l /bin/echo
Delete all .svn files/directories under current directory
find . -name .svn | xargs rm -fr
List all leaf directories of the current directory tree
find . -type d | sort | awk '$0 !~ last "/" {print last} {last=$0} END {print last}'
Write list of missing files in Subversion repository to file removedProjs.
svn status | grep '\!' | cut -d' ' -f2- > removedProjs
Send SIGTERM signal to any process which 'ps' lists as "python csp_build.py"
kill $
Print differences between files in directories folder1 and folder2 recursively, with unified context, ignoring changes in the amount of white space
diff -bur folder1/ folder2/
Convert *.doc files in the current directory tree to the .txt format and remove the original files
find . -name '*.doc' | while read i; do antiword -i 1 "${i}" >"${i/doc/txt}" && rm "${i}"; done
Save the absolute path of "$path" to variable "full_path"
full_path=`readlink -fn -- $path`
search for all the regular files that have been changed in the last 48 hours and sync these to another folder
find /my/source/directory -ctime -2 -type f -printf "%P\n" | xargs -IFILE rsync -avR /my/./source/directory/FILE /my/dest/directory/
Print the list of directories residing in the current directory tree
find . -type d -exec ls -ld {} \;
find all the files which end with ".deb" and display their base name
find . -name '*.deb' -exec basename {} \;
Mount all filesystems in /etc/fstab
sudo mount -a
Search all non-hidden files in the current directory and all non-hidden sub-directories for the file hi.dat.
find *-name hi.dat
Find all SGID files
find / -perm /g=s
List the names of the directories in current directory without going into sub-directories
find . -maxdepth 1 -mindepth 1 -type d -printf '%f\n'
Find all index.* files/directories under current directory
find -name 'index.*'
Count the number of lines in "testfile" wrapped to fit in a width of "$COLUMNS" characters
fold -w "$COLUMNS" testfile | wc -l
Find all directories starting from / that have permissions 777
find / -type d -perm 0777
Locate the httpd.conf file on the system
find / -name httpd.conf
Change permissions to u=rwx,g=rx,o= for all directories in the current directory tree
find . -type d -exec chmod u=rwx,g=rx,o= '{}' \;
Descend into every directory under /etc and print the file/directory names with relative paths
find /etc -execdir echo "{}" ';'
ssh into default vagrant host without running "vagrant ssh" and without an interactive ssh shell
vagrant ssh-config --host default | ssh -F /dev/stdin default
Save the absolute path of the current script to variable "SELF"
SELF=$
Search for files/directories with a case insensitive .txt extension in entire file system
find / -iname '*.txt'
Find all files/directories under Mainfolder directory and redirect the output to outputfle
find Mainfolder > outputfile
Search in current directory downwards all files whose size is 10 bytes .
find . -size 10c -print
List all regular files in /var/www and below that have changed in the last 10 minutes
find /var/www -cmin -10 -type f -printf "%c %pn"
Takes folder name of file $0, changes backslashes to forward ones and saves result in $basedir variable.
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
searches through the root filesystem ("/") for the file named Chapter1, and prints the location
find / -name Chapter1 -type f
display all the files with the names "name1" and "name2" in the current folder and do not search in the sub directories
find . -maxdepth 1 -name "name1" -o -name "name2"
Find broken symlinks in the current directory tree
find -type l | while read f; do if [ ! -e "$f" ]; then ls -l "$f"; fi; done
Find files and directories newer than CompareFile under current directory
find . -newer CompareFile -print
Find all files except files with '.gz' extension in the current directory non-recursively and compress them with gzip
find . -maxdepth 1 -type f ! -name '*.gz' -exec gzip "{}" \;
List PIDs of children processes
ps -o pid --no-headers --ppid $PARENT_PID
Make directories "project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat/a}" as needed and do not cause an error if it exists
mkdir -p project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat/a}
Find all *.mp3 (case insensitive) files/directories under /tmp and remove them
find /tmp -iname '*.mp3' -print0 | xargs -0 rm
Attempt to connect as root to localhost and copy /home/reportuser/dailyReport.doc to directory /root/dailyReports/20150105/ - this will normally fail because ssh won't accept root connections by default.
scp -p /home/reportuser/dailyReport.doc root@localhost:/root/dailyReports/20150105/
Find all *.htm files under current directory and print the changed names by appending 3 levels of parent directory names at the beginning and modifying the actual name to dd-nnn format
find -type f -name "*.htm" | sed 's@^./@@g;s@/@-@g' | awk -F'-' '{print $1 "-" $2 "-" $3 "-" substr "-" $5}'
Remove the "^M" characters from all *.ext files under /home directory
find /home -type f -name "*.ext" -exec sed -i -e "s/\x0D$//g" {} \;
Push the current directory path to the dirs stack
pushd `pwd`
find the most recently changed files under current directory
find . -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort
Keep only the last two hyphen-separated sections of "abc-def-ghi-jkl"
echo "abc-def-ghi-jkl" | rev | cut -d- -f-2 | rev
Copy current working directory to clipboard
pwd | xsel -i
Find all regular files under current directory and replace every occurrences of 'toreplace' with 'replace' in those files
find . -maxdepth 1 -type f -print0 | xargs -0 sed -i 's/toreplace/replaced/g'
Compose filepath as folder path where file $f is located, and lowercase filename of $f file, and save it in 'g' variable
g=`dirname "$f"`/`basename "$f" | tr '[A-Z]' '[a-z]'`
Count the number of times that a single "-----------\n" separated record contains both "A=2" and "dummy=2" in compressed file "file.gz"
zcat file.gz | awk -v RS="-----------\n" '/A=2[ ,\n]/ && /dummy=2[ ,\n]/{count++} END{print "Final counter value=",count}'
Find files/directories greater than 10MB in your home directory
find ~ -size +10M
Display all files in a folder
find man5 -print
Search the current directory tree for files last accessed more than 10 days ago
find . -atime +10
Find all regular files on the system whose names are 'myfile'
find / -name myfile -type f -print
Gets list of IP addresses of all network interfaces.
ifconfig | grep -Eo 'inet ?{3}[0-9]*' | grep -Eo '{3}[0-9]*' | grep -v '127.0.0.1'
Search the current directory for all files with no 'read' privilege for 'others'
find . -maxdepth 1 ! -perm -o=r
Copies file 'index.html' to each top-level directory in the current directory.
find . -mindepth 1 -maxdepth 1 -type d| xargs -n 1 cp -i index.html
Print file information of command "bash"
echo $(ls -l $)
find all the files that have been modified today
find /tmp/test/* -mtime +0
Count case insensitive absolute paths recursively from the current directory
find -type f -exec readlink -m {} \; | gawk 'BEGIN{FS="/";OFS="/"}{$NF=tolower;print}' | uniq -c
Find all *.xml.bz2 files under current directory and run the command find_graph with -build_graph, $i.graph and $i as it's arguments where $i is expanded to each file path
for i in `find . | grep ".xml.bz2$"`; do find_graph -build_graph $i.graph $i; done
display all the regular/normal files ending with ".mod" in a folder
find "$dir" -name "*.mod" -type f -print0
Search for all files and directories named foo, FOO, or any other combination of uppercase and lowercase characters beneath the current directory.
find . -iname foo
Search in current directory downwards all files whic have permission 777 .
find . -perm 777 -print
Find all regular files under $SOURCE directory tree that were modified more than $KEEP days ago and show only the names without the paths
find $SOURCE -type f -mtime +$KEEP | sed ‘s#.*/##'
Find recursively the files named "file" in the current directory ignoring all .git directories
find . -name .git -prune -o -name file -print
Copies file '/boot/config-`uname -r`' to the '.config', printing info message and prompting before owerwriting files.
cp -vi /boot/config-`uname -r` .config
Find all orm* files/directories under current directory
find . -name 'orm*'
Find all *.jpg files under current directory and print only unique names
find . -name *.jpg | uniq -u
Find all *.foo files under current directory and print their contents
cat $(find . -name '*.foo')
Search the current directory recursively for directories with the execute permission set for everybody
find -type d ! -perm -111
List all *.txt files/directories under /etc
ls -l $
search for all the files in the current directory which have been modified in the last 24 hours.
find . -mtime -1
move all the files in the current folder to temp folder and search atleast in one subfolder
find . -mindepth 1 -print0|xargs -0 -I, mv , /tmp
Sets shell options 'globstar' and 'nullglob'.
shopt -s globstar nullglob
Evaluate the output of recursively changing the owner and group of "/data/*" to "mongodb"
`sudo chown -R mongodb:mongodb /data/*`
search for all the directories in the current folder and save the output to a variable
dirs=($)
change owner and group of the file dir1 to user root and group specialusers
chown root:specialusers dir1
List all files in maximum 2 levels down the current directory
find . -maxdepth 2 -type f -exec ls -l {} \;
set variable "uname_m" to machine architecture, ie. x86_64
uname_m=`uname -m`
Delete interactively all the files/directories with inode number 782263 under current directory tree
find . -inum 782263 -exec rm -i {} \;
Print all filenames under /proc and below
find /proc -print0 | xargs -0
Search the current directory tree for all files except SVN ones
find . | grep -v \.svn
Search for a line starting with 'use strict' in all files with '.pl' extension under current directory tree and show the unmatched files only
find . -name '*.pl' | xargs grep -L '^use strict'
Find all *.txt file in the entire system and copy them to /tmp/txt
find / -iname '*.txt' | xargs --replace=@ cp @ /tmp/txt
Execute 'echo -e "\tHello World"' every 2 seconds
watch 'echo -e "\tHello World"'
delete all the php files in the folder /var/www
find /var/www/*.php -type f -exec rm {} \;
display all the soft links in a folder which are not broken
find -L /target ! -type l
search for the file "myfile" in the current folder and display all errors apart from permission denied error
find . -name myfile |& grep -v 'Permission denied'
Counts the number of lines in each file in a git repository, if file names may contain spaces.
git ls-files -z | xargs -0 wc -l
Forcefully remove files *~important-file
rm -rf *~important-file
Find all .java files starting from the current folder
find * -name "*.java"
search for al cpp files in current folder and display distinct parent directory of these files in sorted order
find . -name "*.cpp" -exec dirname {} + | sort -u
Display the number of sub-directories for all directories under current directory tree, sort them according to the decreasing order of the number and show only the first 10 of them
find . -type d -ls | awk '{print $4 - 2, $NF}' | sort -rn | head
Remove all files whose names end with "~" in the /home/peter directory tree
find /home/peter -name *~ -print0 |xargs -0 rm
find all the normal files in the home directory which have been accesed in the last 30 days with the size greater than or equal to 100k.
find $HOME -type f -atime +30 -size 100k
Add cron lists from "filename" to list of cron jobs, giving errors for any lines that cannot be parsed by crontab.
crontab filename
search for a word in all the php files in the current folder and display the matching lines
find . -name \*.php -type f -exec grep -Hn '$test' {} \;
Find all files starting from the current directory that match regular expression '.*Message.*\.java'
find . -print | grep '.*Message.*\.java'
Print numbered list of all third-level files under the current directory
ls -d -1 $PWD/**/*/* | cat -n
Installs all packages from a '/home/pkglist.txt' list, answering 'yes' on all questions.
cat /home/pkglist.txt | xargs yum -y install
search the file "myfile.txt" in home folder
find "$HOME/" -name myfile.txt -print
find regular files in the "mail" folder under the user's home directory, displaying filenames and lines that contain the text "Linux"
find ~/mail -type f | xargs grep "Linux"