nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
list all zero-length files under the current directory
find . -empty -exec ls {} \;
find all the directories in the current folder which have been modified in 24 hours and move them to the folder /path/to/target-dir
find . -type d -mtime -0 -print0 | xargs -0 mv -t /path/to/target-dir
find all the files in the entire file system whose size is exactly 15MB
find / -size 15M
Search the current directory tree for directories that can be opened by noone
find -type d ! -perm -111
Set IFS variable to empty before reading a line of standard input without backslash escape characters
IFS= read -r line
find all files and directories that have been modified in the last seven days
find . -mtime -7
Find broken links
find / -type l -print0 | xargs -0 file | grep broken
display all regular/normal files in the current folder with the name dummy
find -type f -name dummy
Write a random list of numbers to /tmp/lst and stdout.
seq 1 10 | sort -R | tee /tmp/lst |cat < < **...**
Print the commands that would execute "myfile" on all .ogv files from the current directory tree
find ./ -name *.ogv -exec echo myfile {} \;
Infinitely print "no" to the screen
yes no
Search the file system for regular files whose names are shorter than 25 characters
find / -type f|egrep "/[^/]{0,24}$"
Find files associated with an inode
find . -inum 968746 -print
Find all *FooBar* files/directories under current directory and copy them to ~/foo/bar
find . -name "*FooBar*" -exec sh -c 'cp -- "$@" ~/foo/bar' sh {} +
Recursively removes all files and folders like 'FILE-TO-FIND' from current folder.
find . -name "FILE-TO-FIND" -exec rm -rf {} +
Find directories that are directly under /home/user/workspace directory and were modified more than 30 days ago and print a message saying that the directory wasn't modified during last 30 days
find /home/user/workspace -mindepth 1 -maxdepth 1 -type d -mtime +30 -execdir echo "It seems that {} wasn't modified during last 30 days" ';'
print all PIDs of stopped processes
jobs -sl | awk '{print $2}'
Find all *.java files under current directory and archive them to myfile.tar
find . -type f -name "*.java" | xargs tar rvf myfile.tar
Find files in the "dir" directory tree whose names are 33 characters in length
find dir -name '?????????????????????????????????'
Find every file under the directory /home owned by the user joe.
find /home -user joe
find files in the current directory with pattern` '*.[ch]' which are contain ‘thing’ string and print file names
find . -name '*.[ch]' | xargs grep -l thing
Delete all .svn files/directories under current directory
find . -name .svn |xargs rm -rf
compresses all the files in the current folder with default depth
find . -depth -print | cpio -dump /backup
Save the directory of the full path to the current script in variable "dir"
dir=$(dirname $(readlink /proc/$$/fd/255))
Find all *.rb files under current directory and change their mode to 600
find . -name "*.rb" -type f -exec chmod 600 {} \;
Remove files in current directory according to the filenames found in ~/clang+llvm-3.3/bin/
find ~/clang+llvm-3.3/bin/ -type f -exec basename {} \; | xargs rm
create directories foo and bar
mkdir foo bar
Make 3 directories named "~/Labs/lab4a/folder" followed by the number 1, 2, or 3
mkdir ~/Labs/lab4a/folder{1,2,3}
Execute awk script "script.awk" with 2 arguments both "file.txt" and format the output as a table
awk -f script.awk file.txt{,} | column -t
List all broken symlinks including cyclic links under current directory
find . -type l -exec test ! -e {} \; -printf '%Y %p\n'
Find all files/directories under '/var/tmp' directory tree that belong to a user with user id 1000
find /var/tmp -uid 1000
Calculate the md5 sum of all files in the current directory with the filename printed first
ls -p | grep -v / | xargs md5sum | awk '{print $2,$1}'
Find all regular files starting from the current directory
find . -type f
Prints full path to files in a current folder.
ls -d $PWD/*
Find all regular files undee '/usr/bin' directoryt tree that are less than 50 bytes in size
find /usr/bin -type f -size -50c
Find all files/directories with '.tar.gz' extension under $DIR/tmp/daily/ directory tree, sort them numerically and show the last 3 of them
find $DIR/tmp/daily/ -name '*.tar.gz' | sort -n | tail -3
Try to determine the type of contents in "myfile" located in user's home directory.
file ~/myfile
change owner of the file my_test_expect.exp to user el
sudo chown el my_test_expect.exp //make el the owner.
Get a list of directories owned by group ID 100
find / -type d -gid 100
Add "prefix" to every non-blank line in "file.txt"
nl -s prefix file.txt | cut -c7-
Prints day of first Tuesday in a month.
cal | awk 'NR>2{Sfields=7-NF; if {printf "%02d\n",$3;exit}}'
Check if directory $some_dir is empty
find "`echo "$some_dir"`" -maxdepth 0 -empty
Create a symolic link in "/usr/local/" to "/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"
ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/
Count the number of lines in all files in the xargstest/ directory tree that match pattern 'file??'
find xargstest/ -name 'file??' | sort | xargs wc -l
search for regular/normal file with the name "myfile" in the entire file system
find / -name myfile -type f -print
Print A record for domain 'domain.' from 8.8.8.8 nameserver
dig @8.8.8.8 domain. a
Find all files that are modified in last 3 days
find . -type f -mtime -3
Finds shell options with 'login' in name.
shopt | grep login
find all the .jpg files in / and copy them to the current folder.
find / -type f -name *.jpg -exec cp {} . \;
create a backup of all the files in the folder /tmp and display the taken for this operation
timex find /tmp -print|backup -ivqf/dev/null
Display all lines containing UTRACE in the current kernel's compile-time config file.
grep UTRACE /boot/config-$
display all the files in the current folder which do not belong to any user
find . -nouser
Force delete all the regular/normal files in the current folder and do not search in the sub folders (print0 is used to handle files which have newlines in their names or files with the name only as spaces )
find . -maxdepth 1 -type f -print0 | xargs rm -f
Create new crontab set including $job and only jobs from current crontab that don`t contain $command
cat <(fgrep -i -v "$command" <(crontab -l)) <(echo "$job") | crontab -
find in the entire file system for the file mysql
sudo find / -name mysql -print
Search the current directory tree for all files matching regular expression ".*\.rb$"
find . -regex ".*\\.rb$"
Find all *.xml.bz2 files under current directory
find . -name \*.xml.bz2
Print $d if $d is empty
find "$d" -prune -empty
Change to location of '$TARGET_FILE' file.
cd `dirname $TARGET_FILE`
send GET request to "https://graph.facebook.com/me/feed" using URL-encoding "access_token=$"
curl -v --get --data-urlencode "access_token=$" https://graph.facebook.com/me/feed
find regular files which modification time is 7 days ago
find . -mtime -7 -type f
Find all files in the current directory tree with extension .html and replace all occurences of "php" with "html" inside them
find ./ -type f -name *".html" | xargs sed -i "s/php/html/g"
find all the files in the file system which hae set uid enabled and save them to /root/suid.txt and those which have size greater than 100MB save them to /root/big.txt
find / \ ,
Read hexadecimal bytes from device "/dev/midi1"
od -vtx1 /dev/midi1
Fix files to default permissions 755
find . -type d -exec chmod 755 {} \;
Search case insensitively for 'foo' in all the files with '.java' extension under current directory tree and show only the file names
find . -type f -name "*.java" -exec grep -il 'foo' {} \;
Find all directories in the current directory tree whose names do not contain '.' and move their contents to the current directory
find . -type d ! -iname '*.*' | while read d; do mv $d/* .; done
Find all files under $dir directory
find "$dir" -type f
Find files newer than `tmpfile' starting from the current directory
find . -newer tmpfile
Locate symbolic links in /usr and below
find /usr -type l
display all the files in the current folder which have been modified in the last 14*24 hours
find . -mtime -14 -print
Send two ping requests to "www.google.com"
ping -c 2 www.google.com
Recursively copy all files and folders in the current directory excluding "exclude_pattern" to "/to/where/"
rsync -r --verbose --exclude 'exclude_pattern' ./* /to/where/
display long listing of all the empty files in the current folder
find . -empty -exec ls -l {} \;
returns the first 100 bytes in the file
head -c 100 file
Find all files under current directory
find -type f
Remove all files and directories called "test" from the current directory tree
find . -name test -exec rm -R "{}" \;
Use 'top' to monitor process 'a.out'
top -b -p `pidof a.out`
Append "foo" and "bar" column in file "file" with values dependent on the current table contents
awk 'NR==1 {print $0, "foo", "bar"; next} {print $0, ($2=="x"?"-":"x"), ($4=="x"?"-":"x")}' file | column -t
Write the list of regular files in the current directory tree to files /tmp/grep1 and /tmp/grep2
find ./ -type f | tee /tmp/grep1 /tmp/grep2 >/dev/null
Find all files/directories in 1 level down the current directory
find -mindepth 1 -maxdepth 1
Print the contents of "$FILE" starting from line 2
tail -n +2 "$FILE"
List environment variables and their values, escaping all semicolons with a backslash.
env | sed 's/;/\\;/g'
Find all .txt files in current directory and rename with .html .
find . -type f -name "*.txt" -exec mv {} `basename {} .html` .html \;
Search directory foo for files containing "foo/bar" in their full names
find foo -path foo/bar -print
Search the /tmp directory tree for files owned by user `ian'
find /tmp -user ian
find all the files in the current folder that have been modified in the last 24*3 hours
find ./ -mtime -3
List all environment variables
set
Read a single character from standard input with prompt "Is this a good question (y/n)?" and save the response to variable "answer"
read -n 1 -p "Is this a good question (y/n)? " answer
Find files with 002 permission in entire file system and print them with the string 'has world write permissions' printed at last
echo $(find / -type f -perm -002) has world write permissions
Find files with group write permission and remove the permission
find . -perm -20 -exec chmod g-w {} ;
Find all regular files in the current directory tree ignoring directory ./source/script
find . -path ./source/script -prune -o -type f -print;
Remove files named "core" from the /work directory tree and write their names to /dev/stderr (the standard error
find /work \ , \
Find all regular files under $DIR directory tree with ".$TYPE" extension (case insensitive) where $TYPE expands in the current shell
find $DIR -type f -iname "*.$TYPE"
Print the IP addresses of the host name
hostname -I
List each file or directory in the current directory prefixed with its filesize in MB and sorted from smallest to largest
du -smc * | sort -n
Delete all hidden files under $some_directory
find "$some_directory" -type f -name '.*' -delete
Find directories in the current directory tree that were modified within the last 24 hours and move them to /path/to/target-dir
find . -type d -mtime -0 -exec mv -t /path/to/target-dir {} +
Delete all filename* files under /dir directory
find /dir -name "filename*" -type f -print | xargs rm
Continuously answer "y" to any prompt from "mv ..."
yes | mv ...