nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
List all files/directories under current directory ensuring white space safety
find -print0 | xargs --null
display all the files and directories with the name "CVS" from /usr/src folder that are at least seven levels deep and do not descend onto the folders
find /usr/src -name CVS -prune -o -depth +6 -print
Interpret all lines containing an equal sign in myfile
grep "=" myfile | source /dev/stdin
Prints long listing of directory $var sorted from oldest to newest, with appended indicators.
$ ls -Fltr $var
List all files in the current directory tree that were last modified between "mar 03, 2010 09:00" and "mar 11, 2010"
find -newermt "mar 03, 2010 09:00" -not -newermt "mar 11, 2010" -ls
Search the current directory tree for directories lacking execute permissions for user, group, or others
find . -type d ! -perm -111
Exclude directory from find . command
find ./ -path ./beta/* -prune -o -iname example.com -print
Monitor 3 specific process IDs: 18884, 18892, and 18919 (GNU specific)
top -p 18884 -p 18892 -p 18919
Copy a file xyz.c to all the directories below the current one whose names begin with "temp"
find . -type d -name "temp*" | xargs -n1 cp xyz.c
Copy all files in the current directory except those containing 'Music' to '/target_directory'.
cp `ls | grep -v Music` /target_directory
Print file type information of the "java" executable
cat `which java` | file -
find all files with pattern` '*.mp3'
find / -name *.mp3
Go to /tmp directory.
cd /tmp
Find all files and directories under current directory without crossing over to other partitions and archive them into path_to_save.cpio.gz
find . -xdev -print0 | cpio -oa0V | gzip > path_to_save.cpio.gz
Lists all subdirectories in a current folder, removing trailing slash.
ls -d */ | cut -f1 -d'/'
Copy all files that match 'FooBar' in their paths under current directory tree to the '~/foo/bar' directory
find . | grep "FooBar" | tr \\n \\0 | xargs -0 -I{} cp "{}" ~/foo/bar
find all case-insensitive php or pthml files, which whole path does not contain /some/directory case-insensitivily , and excute xgettext which whole name as parameter
find /project/directory -iname '*.php' -or -iname '*.phtml' | grep -iv '/some/directory' | xargs xgettext
Print the contents of "numbers.txt"
cat numbers.txt
rename all the text files in the current folder to html files
find -name "*.txt" -exec mv {} `basename {} .htm`.html \;
Saves in 'result' variable list of groups which user $line belongs to, and not matching pattern "_unknown|sciences|everyone|netaccounts"
result=$
find httpd.conf file in /etc directory
find /etc -name "httpd.conf"
Change to the directory of the executable "python"
cd `dirname $`
Find all xml files under current directory and archive them to .bz2 archives
for i in `find . | grep ".xml$"`; do bzip2 $i; done
Change the owner of "process" to "root"
sudo chown root process
Find all files under current directory and rename them by replacing all white spaces with _
find ./ -name "* *" -type f -d 1 | perl -ple '$file = $_; $file =~ s/\s+/_/g; rename;'
Search /usr/local for subdirectories whose names end with a number 0-9
find /usr/local -maxdepth 1 -type d -name '*[0-9]'
List the entire cron job list of user "apache".
crontab -u apache -l
Mount the "vboxsf" filesystem "myFileName" on "~/destination"
sudo mount -t vboxsf myFileName ~/destination
Find all regular files in the the user's home/mail directory and search for the word "Linux".
find ~/mail -type f | xargs grep "Linux"
Split "file.tar.gz" into files of size 1024 MB with a prefix of "file.tar.gz.part-"
split -b 1024m "file.tar.gz" "file.tar.gz.part-"
update the permission of all the php files in current directory and save the output to a file
find . -name '*.php' -exec chmod 755 {} \; > logfile.txt
search for a pattern in all the python files in the current folder. and save the output to output.txt file. print0 is used to handle files with newlines in their names
find . -name '*.py' -print0 | xargs -0 grep 'something' > output.txt
Search the ~/Books directory recursively for files named "Waldo"
find ~/Books -name Waldo
Format the contents of "[file]" in a neat table
cat file | column -t
Find all pdf files excluding *_signed.pdf files under /some/dir with null character as the delimiter
find /some/dir -name "*.pdf" ! -name "*_signed.pdf" -print0
Find all "YourProgramName" regular files in the current directory tree and print the full paths to the directories containing them
find . -type f -name YourProgramName -execdir pwd \;
print command for alias "list" with low priority command
nice -10 `alias list | sed "s/^\\?[^=]\+='//; s/'$//;"`
Find all files under current directory whose status was changed less than 3 days ago, sort them and show last 5 lines of output with only their paths
find . -type f -ctime -3 -printf "%C@ %p\n" | sort | tail -n 5 | sed 's/[^ ]* \/\1/'
Create intermediate directories "full", "path" as required and directory "to"
mkdir -p `dirname /full/path/to/file.txt`
find all files under the current directory that end in "foo" and execute somecommand on each quoted filename
find . -name "*.foo" -exec somecommand "{}" \;
Find all broken symlinks under /path/to/search directory
find /path/to/search -xtype l
Stores date of last month day in the 'lastdaymonth' variable.
set lastdaymonth=`cal $month $year |tr -s " " "\n"|tail -1`
Removes first and last parts of path $path and saves the result in 'finalName' variable.
finalName=$(basename -- "$(dirname -- "$path")")
find all the files in the current folder which do not have the execute permission
find . -type d ! -perm -111
Change onwer of "file" to "user_name"
chown user_name file
Find all *.zip files under current directory and unzip them in the same directory as the files
find . -name '*.zip' -exec sh -c 'unzip -d `dirname {}` {}' ';'
Allow all users to execute "myscript.sh"
chmod a+x myscript.sh
Print the unique lines from standard input preserving the order they appear
nl -n ln | sort -u -k 2| sort -k 1n | cut -f 2-
Format contents of "file" as a table
paste -d" " - - < file | column -t
Sort strings of 'test.txt' file by second from the end field
rev test.txt | sort -k2 | rev
Find all regular files with permissions 777 under and below /home/user/demo/
find /home/user/demo -type f -perm 777 -print
Find all files under current directory that are read less than 1 minute ago
find . -amin -1
Find command will list of all files & directories from current directory , before listing echo command will display ' List of files & Directory '
find . -exec echo ' List of files & Direcoty' {} \;
delete all the files in the current folder which end with ".bak" or ".backup" and which have not been accessed in the last 30 days
find . -type f -atime +30 -exec rm '{}' ;
Create tar.gz files older than one day logs
find /home/testuser/log/ -mtime +1 | xargs tar -czvPf /opt/older_log_$(date +%F).tar.gz
Print which files differ in "dir1" and "dir2" recursively
diff -qr dir1 dir2
find all the directories with the name "uploads" in current folder
find . -type d -name 'uploads'
search the word "MySearchStr" in all the regular/normal files in the current folder and display the line number and the file name
find . -type f -print0 | xargs -0 -e grep -nH -e MySearchStr
find all the mp3 files in the current folder and move them to another folder
find . -name "*.mp3" -exec mv {} "/Users/sir/Music//iTunes/iTunes Media/Automatically Add to iTunes.localized/" \;
Copies all files like "*FooBar*" under the current directory to the '~/foobar' directory.
find . -name '*FooBar*' -exec cp -t ~/foobar -- {} +
Return a list of files newer than file poop
find . -mnewer poop
display all the directories in the current folder which start with processor followed by digit and ends with .1 or .2
find . -type d -regextype posix-egrep -regex '\./processor[0-9]*/10\.'
Find all executable symlinks or upvoter-* files under maximum 1 level down the {} directory
find {} -name 'upvoter-*' -type f -or -type l -maxdepth 1 -perm +111
Selects a job from list and get it back to the foreground .
fg `jobs | iselect -a | grep -o [0-9]*`
Split "$INFILE" into files of at most "$SPLITLIMT" with a numeric suffix and a prefix "x_"
split -d -l $SPLITLIMT $INFILE x_
Find all *.mov files under current directory and run an ffmpeg command with the path and the name for each file
find . -iname "*.mov" -printf "%p %f\n" | xargs -r -n2 ffmpeg -f flv -i
Find all the files whose name is tecmint.txt
find . -name tecmint.txt
Change permissions to 755 for all subdirectories of the current directory
find . -type d -print | sed -e 's/^/"/' -e 's/$/"/' | xargs chmod 755
Locate all files in the current directory and below that have "testfile" in their names regardless of the case
find -iname "*TESTFILE*"
Finds all the log* files in /myDir recursively that are more than 7 days older, skipping already created .bz2 archives and compresses them.
find /myDir -name 'log*' -and -not -name '*.bz2' -ctime +7 -exec bzip2 -zv {} \;
Find all *.mp3, *.aif*, *.m4p, *.wav, *.flac files under $musicdir directory
find "$musicdir" -type f -print | egrep -i '\.(mp3|aif*|m4p|wav|flac)$'
search for the file, filename.txt in the current folder
find . -name filename.txt
Find all files named "file.ext" in the current directory tree and print the path names of the directories they are in
find `pwd` -name file.ext |xargs -l1 dirname
find all the files from root folder which have nogroup or noname and dispaly their details.
find / \( -nogroup -o -noname \) -ls
Print every three lines of "file" as a comma separated line
paste -sd',,\n' file
Find all *.txt files under current directory, change their permission to 666 and copy them to /dst/ directory
find . -name \*.txt -exec chmod 666 {} \; -exec cp {} /dst/ \;
display all the directories in the current folder excluding those that are present in the folder secret
find . -name secret -type d -prune -o -print
Recursively finds all *.dbf files from the root folder and prints list of folders with such files.
find / -name "*.dbf" -exec dirname {} \; 2> /dev/null | sort -u
display a long list of all regular/normal files in the file system which belong to the root and with suid bit set
find / -type f -user root -perm -4000 -exec ls -l {} \;
Search the current directory tree for files whose names do not end in "1" and "2"
find . -type f ! -name "*1" ! -name "*2" -print
Execute "du -s path" every 300 seconds
watch -n 300 du -s path
List the largest file in long list format of all the files under the current directory
find . -type f -ls | sort -nrk7 | head -1 #unformatted
Prints all child processes of a process with id 20238.
pstree -p 20238 | sed 's/(/\n(/g' | grep '(' | sed 's/(\(.*\)).*/\1/'
Delete files containing whitespaces without recursion
find . -name '*[+{;"\\=?~<>&*|$ ]*' -maxdepth 0 -exec rm -f '{}' \;
Find *.avi and *.flv files in /path/to/your/directory and below and copy them to /path/to/specific/folder
find /path/to/your/directory -regex '.*\.\' -exec cp {} /path/to/specific/folder \;
Uncompress "archive.tar.gz" and extract the archive to "/destination"
gzip -dc archive.tar.gz | tar -xf - -C /destination
Find all regular files named 'Waldo' under 'Books' directory tree that is located in user's home directory
find ~/Books -type f -name Waldo
Print the first 24 alphanumeric characters from "/dev/urandom", determining C locale for all categories
cat /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9' | fold -w 24 | head -n 1
List all files 2 levels deep in the current directory tree
tree -L 2 -fi
Find all directories under current directory and set their permission to 775
find -type d exec chmod 775 {} +
Report file systems disk usage in kilobytes.
df -k
Find all files in the current directory tree that match pattern 'a(b*'
find . -name 'a(b*' -print
Creates temporary file, replacing XXXXXXXXXXXXXXXXXXXXXXX with equal length suffix.
mktemp /tmp/banana.XXXXXXXXXXXXXXXXXXXXXXX.mp3
find all the files which have the write permission to the group and remove the write permission.
find . -perm -20 -exec chmod g-w {} ;
List all cron jobs where the minute part is either * or a number from 0 to 14.
crontab -l | awk '$1 == "*" || $1 ~ /^[0-9]+$/ && $1 < 15 {print}'
Copies newest file under the current folder to the '/tmp/'
cp $ /tmp/
Find all *.dbf files/directories in entire file system
find / -name "*.dbf"
create a backup of all the files which have been modified in the last 48 hours
find source/directory -ctime -2 | cpio -pvdm /my/dest/directory
Dump "filename" as 2 byte wide hexadecimal and printable characters
od -xc filename
Pair side-by-side content of the 'file' and its side-mirrored content
paste -d ' ' file <