nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Compress all directories found in directory tree $LOGDIR that have been modified within the last 24 hours
find $LOGDIR -type d -mtime -1 -exec compress -r {} \;
search for all the files in the current directory which have the group staff and have write permission enabled to the user and display them.
find . -group staff -perm -2000 -print
Print second field from semicolon-seprated line <line>.
echo "<line>" | cut -d ";" -f 2
Remove the regular files from the current directory that were last modified on November, 22
find -maxdepth 1 -type f -newermt "Nov 22" \! -newermt "Nov 23" -delete
Search the current directory for files whose names start with "messages." ignoring SVN, GIT, and .anythingElseIwannaIgnore files
find -name 'messages.*' -exec grep -Iw uint {} + | grep -Ev '.svn|.git|.anythingElseIwannaIgnore'
Find recursively the latest modified file in the current directory
find . -type f -print0|xargs -0 ls -drt|tail -n 1
Change permission to 000 of all directories named '.texturedata' under '/path/to/look/in/' directory tree
find /path/to/look/in/ -type d -name '.texturedata' -prune -print0 | xargs -0 chmod 000
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 \
display all the files ending with ".user" or beginning with "admin" or ending with ".user.gz" in /var/adm/logs/morelogs/ and excluding all regular files
find /var/adm/logs/morelogs/* -type f -prune \ -print
Find all files/directories excluding paths that match '.git' or '.gitignore'
find -print0 | grep -vEzZ '(\.git|\.gitignore/)'
Request that the master ssh connection "officefirewall" exits
ssh -O exit officefirewall
cope *.mp3 files to /tmp/MusicFiles
find . -type f -name "*.mp3" -exec cp {} /tmp/MusicFiles \;
Print history with the first field removed
history | awk '{sub; sub; print}'
Archive file 'file' with bzip2 tool, store compressed data to a file 'logfile' and also print to screen
bzip2 -c file | tee -a logfile
Copy all files in the current directory tree matching "textToSearch" to "$destination_path"
find . -type f | xargs grep -l "textToSearch" | cpio -pV $destination_path
Print number of bytes in $file.
cat $file | wc -c
Count and show the number of lines for each PHP files in the current directory tree
find . -name '*.php' | xargs wc -l
search for a regular/normal file "myfile" in the entire file system excluding the folder in excluded_path
find / -path excluded_path -prune -o -type f -name myfile -print
find all the jar files in the current folder and display all the ".class" files or files ending with jar
find . -name “*.jar” -print -exec jar tvf {} \; |grep -E “jar$|.class”
search for the word foo in all the js files in the current folder
grep -iH foo `find . -name "*.js"`
Add executable permission to "pretty-print"
chmod +x pretty-print
Show the files or directories in the current directory whose names are not "MyCProgram.c"
find -maxdepth 1 -not -iname "MyCProgram.c"
display all the text files in the home folder
find /home -name "*.txt"
Search the current directory tree for the files with extension "trc" and list them if they are more than three days old
find . -name "*.trc" -ctime +3 -exec ls -l {} \;
Replace "-" with "0" in columns 4 and 5 of file "test.in" and format as a table
awk '{gsub;gsub}1' test.in | column -t
Find all files whose names contain the string 'xpilot' which exist within '/usr/local/games'
find /usr/local/games -name "*xpilot*"
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/
Find all files/directories under current directory with 'foo' in their paths and copy them to ~/bar
while read line ; do cp "$line" ~/bar ; done < <
Lists all files in a current folder, separating names with comma.
ls -m
list all samba files in /var/l* directory
find /var -path */l??/samba*
Find files/directories named 'foo' under current directory tree without descending into directories named 'foo'
find . -name foo -type d -prune -o -name foo -print
Print content of 'domains.txt' with removed first one of dot-delimited fields
rev domains.txt | cut -d '.' -f 2- | rev
change html files to mode 644
find /usr/local -name "*.html" -type f -exec chmod 644 {} \;
Prints long listing of directories "./my dir" and "./anotherdir" sorted from oldest to newest, with appended indicators.
$ ls -Fltr "./my dir" "./anotherdir"
Remove with prompting all files that have not been accessed in over 100 days
find /mydir -atime +100 -ok rm {} \;
remove all the files with the name "Trash" in the folder /home
find /home -name Trash -exec rm {} \;
Find all files/directories that start with 'test' in their names under current directory tree
find . -name 'test*'
Unset IFS and read a single character of standard input with no echo and save the response in variable "SELECT"
IFS= read -s -n 1 SELECT
Search for the regex '[0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*' in all files under /etc
find /etc -exec grep '[0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*' {} \;
Print list of file systems currently mounted.
df -h | awk '{print $1}'
Show system information: kernel name, hostname, kernel release and version, machine architecture, processor type, hardware platform, and operating system type.
uname -a
Copy all files in current directory that do not match */not-from-here/* in their names to /dest
find . -type f -not -iname '*/not-from-here/*' -exec cp '{}' '/dest/{}' ';'
Calculate and show md5 sums for every files under current directory tree
find . -type f -exec md5sum \{\} \;
List all files in the current directory tree that were modified 60 minutes ago
find -mmin 60
Find all files and directories in the current directory with "linkin park" in their names and copy them to /Users/tommye/Desktop/LP, preserving path hierarchy
find . -iname "*linkin park*" > temp;rsync -arhv --files-from=temp /Users/tommye/Desktop/LP;rm temp
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" | awk -F'[/]' 'BEGIN{OFS="-"}{ gsub(/^\.\//,"") ;print $1,$2, substr($4,3,2),substr($4,5,2),substr($4,8) }'
print number of jobs
n_jobs=$
Find links that point to nothing
find / -type l -print | perl -nle '-e || print';
Updates all packages with 'rpmfusion' in name.
find-repos-of-install | grep rpmfusion | xargs yum update
Search the files under and below /directory/containing/files for "pattern_to_search"
find /directory/containing/files -type f -exec grep -H 'pattern_to_search' {} +
Rename all *.jpg files under current directory by appending parent directory name at the beginning of their names
find . -iname '*.jpg' | while read fn; do name=$ ; dir=$ ; mv "$fn" "$dir/$-$name" ;done ./lib/bukovina/version.jpg ./lib/bukovina/bukovina-version.jpg
Remove the "123_" prefix from all filenames of .txt files in current directory.
rename 's/^123_//' *.txt
Print IP addresses of the current host
hostname -I|cut -d" " -f 1
force delete all the files in the current folder expect xml files
find . | grep -v xml | xargs rm -rf {}
Find all files whose names contain the string 'xpilot' which exist within '/usr/local/games'
find /usr/local/games -name "*xpilot*"
Search for *pattern* in and below current directory
find -name "*pattern*"
Find all files in the current directory and below with extension .php and replace "php" with "html" in their names
find ./ -type f -name "*.php" | xargs -r rename "s/php/html/"
Find all files/directories under $dir directory
find "$dir"
find all the files which have not been modified in the last 1 year and display the total disk usage of them in GB
find . -type f -mtime +356 -printf '%s\n' | awk '{a+=$1;} END {printf "%.1f GB\n", a/2**30;}'
Get domain name with 'google' from dig reverse lookup.
dig -x 8.8.8.8| awk '/PTR[[:space:]]/ && /google/ {print $NF}'
Find all files/directories under current directory appending a null character at the end of each file name/path
find -print0
SSH into me@machine, run "./executeMyScript", and spawn a bash shell
ssh -t me@machine ./executeMyScript '&&' bash -i
List all *.gif files found in the current directory tree
find . -name *.gif -exec ls {} \;
Create symbolic links in current directory for all files located in "dir" directory and have filename extension "jpg"
find dir -name '*.jpg' -exec ln -s "{}" \;
check if there any files from the .git folder after excluding it using the prune command
find . -path ./.git -prune -o -print -a \ | grep '.git'
Modify and rewrite 'file' replacing all instances of "foo" with "bar"
sed -i 's/foo/bar/g' file
Search the current directory recursively for files last modified within the past 24 hours ignoring .swp files and paths ./es* and ./en*
find . -mtime 0 | grep -v '^\./en' | grep -v '^\./es' | grep -v .swp
Unzip and expand tar archive "compressFileName"
zcat compressFileName | tar xvf -
find all files in the current folder with the permission 777 and modify the permissions as 755.
find . -type f -perm 777 -exec chmod 755 {} \;
find all files in the current folder which have not been changed in the last 48 hours
find ./ -daystart -ctime +2
change the current working directory to "A" and display all the files in that folder and save the output to the file "tmp.txt"
> tmp.txt
Recursively delete all files/folders named '.svn' in a current folder.
find . -name .svn -delete
List all files in entire file system that are newer than the file $newerthan and older than the file $olderthan in regards of modification time
find / -type f -name "*" -newermt "$newerthan" ! -newermt "$olderthan" -ls
Find all .gz archives in the current directory tree
find . -name '*.gz'
Find all files/directories under /myfiles that were accessed more than 30 days ago
find /myfiles -atime +30
create symbolic links in directory "/usr/local/symlinks " to all files located in directiry "incoming" and that have been modified earlier then 5 days and owned by user "nr"
find /incoming -mtime -5 -user nr -exec ln -s '{}' /usr/local/symlinks ';'
Find files containing `blah' in their names modified less than 2 days ago, case insensitive
find . -iname '*blah*' -mtime -2
Find all index.* files/directories under current directory
find -name 'index.*'
Print numbers from 1 to 5 without separating spaces and without a newline
seq 5 | awk '{printf "%s", $0}'
Finds the folder where temporary files would be written to.
dirname $
List all regular files modified more than 61 days
find -type f -mtime 61 -exec ls -ltr {} \;
Find all files whose name or type description includes "text", display only paths to files.
find . -exec file {} \; | grep text | cut -d: -f1
List the combined path of the current working directory and "file.txt"
ls "`pwd`/file.txt"
Answer "y" to all prompts of "rm -rf foo"
yes | rm -ri foo
Infinitely print "no" to the screen
yes no
copy the file header.shtml to those dirs
find dir1 dir2 dir3 dir4 -type d -exec cp header.shtml {} \;
create a tar ball of all the jpg and png images in the current folder
find . \ -print -exec tar -rf images.tar {} \;
display all the files in the folder a
find a
Print the names of all files in /some/directory and its subdirectories recursively whose MIME type is video
find /some/directory -type f -exec file -N -i -- {} + | sed -n 's!: video/[^:]*$!!p'
finda all the hidden files excluding those having the extension htaccess
find . -type f \( -iname ".*" ! -iname ".htaccess" \)
Search for 'String' case insensitively in all files under current directory tree and show the matched lines with their filenames
find . -name * -print0 | xargs -0 grep -iH "String"
find all directories with the name root in the entire file system.
find / -type d -name root
Find all fglrx-libGL* files under and below debian/fglrx/
find debian/fglrx/ -name 'fglrx-libGL*'
Download "https://s3.amazonaws.com/sampletest/sample.tar.gz", unzip it, and untar it replacing filenames with "old" to "new"
curl https://s3.amazonaws.com/sampletest/sample.tar.gz | gunzip | pax -r -s "/old/new/"
Mathematically sum each line in the output of "..."
echo $(( $ ))
Print login name and full name of all users currently logged in and delete instances of "of group.*"
finger -l | awk '/^Login/' | sed 's/of group.*//g'
Find the "*.foo" files in the current directory tree that are not under ".snapshot" directories
find . -name .snapshot -prune -o -name '*.foo' -print
Print every two lines in "file" on a single line separated by a space
cat file | paste -d' ' - -
Find all files under /path and below writable by `group' and `other'
find /path -perm -go+w
Update the archive '2009.tar' with the files from the data/ directory tree that match pattern 'filepattern-*2009*'
find data/ -name "filepattern-*2009*" | cpio -ov --format=ustar > 2009.tar