nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Find all files on the system whose names are 'composer.json' and search them for "drush"
find / -name composer.json -exec grep -n drush {} /dev/null \;
List all regular files in and below the home directory that have been modified in the last 90 minutes
find ~ -type f -mmin -90 | xargs ls -l
Adds %Pathname% to the dirs stack .
pushd %Pathname%
Dump the character output of "echo 'hi'"
echo 'hi' | od -c
Search the CSS files found in the current directory tree for string "foo"
find . -name \*.css -print0 | xargs -0 grep -nH foo
Find all directories by the name `httpdocs' on the system
find / -type d -name 'httpdocs'
Print position number of day '9' in fourth line of calendar output for September, 2009.
cal 09 2009 | awk 'NR==4{day="9"; col=index; print col }'
Recursively removes all files and folders named '.svn' in a current folder.
find . -name .svn -exec rm -rf {} \;
replace a word in all the regular/normal files in the current folder(doesn't actually modify the original file just displays the replaced text)
find . -type f -print0 | xargs -0 sed -i 's/Application/whatever/g'
List all regular files in and below the home directory that were modified more than 5 years ago
find ~ -type f -mtime +1825 |xargs -r ls -l
list all files in /home/bozo/projects directory tree that were modified within the last day
find /home/bozo/projects -mtime -1
Count the number of all directories under directory '/mount/point' non-recursively
find /mount/point -maxdepth 1 -type d | wc -l
Copies ""$project_dir"/iTunesArtwork", to the 'Payload/iTunesArtwork', rewriting files if necessary.
cp -f "$project_dir"/iTunesArtwork Payload/iTunesArtwork
Rename all *.html files under and below the current directory to *.var
find -name '*.html' -print0 | xargs -0 rename 's/\.html$/.var/'
Update the archive '2009.tar' with the files from the data/ directory tree that match pattern 'filepattern-*2009*'
find data/ -name filepattern-*2009* -exec tar uf 2009.tar {} ;
Archive "/top/a/b/c/d" to host "remote" using relative path names
rsync -a --relative /top/a/b/c/d remote:/
Extract any line in "file1.txt" which does not appear as the first ";" delimited entry in "file2.txt"
comm -23 <(sort file1.txt) <(grep -o '^[^;]*' file2.txt | sort)
List each subdirectory name composing the current working directory
pwd | cut -b2- | tr '/' '\n'
Make a copy of file1 in dir1, dir2, and dir3.
echo dir1 dir2 dir3 | xargs -n 1 cp file1
Starts 'chromium', storing user data in a newly created temporary folder.
(chromium --user-data-dir=$ &)
Creates temporary file in a current folder and saves path to it in 'f' variable.
f=`mktemp -p .`
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 {} \;
Find all *.txt file and replace old word to new word with sed command
find . -type f -name "*.txt" -exec sed 's/TZ/MALAWI/g' {} \;
Delete all MP3 files under /tmp
find /tmp -iname '*.mp3' -print0 | xargs -0 rm
Saves folder path where target of symbolic link $file file is located in 'base' variable.
base=$(dirname $(readlink $file))
unzip all zip files in current folder
find -name '*.zip' | xargs -n 1 unzip
Remove with prompting all files starting in /mydir that have not been accessed in over 100 days
find /mydir -atime +100 -ok rm {} \;
display all symbolic links in the folder "myfiles" and follow them
find -L /myfiles
Find all files/directories under 'A' directory tree excluding the paths containing the directory 'a'
find A \! -path "A/a/*"
Counts lines in each of *.php files in a current folder and subfolders and prints total count as well.
find . -name "*.php" | xargs wc -l
display all the html files in the current folder
find . -name "*.html" -print
Ensure all 5 of UEDP0{1..5}_20120821.csv files exist, creating empty files for any missing ones
touch -a UEDP0{1..5}_20120821.csv
Move all files and directories in the current directory to "/foo"
mv * /foo
find all html or cgi files in current folder
find ./ -type f -iregex ".*\.html$" -or -iregex ".*\.cgi$"
Find all files/directories under $dir directory
find "$dir"
Deletes empty folder 'nonsense_dir'.
rmdir nonsense_dir
search for the word error in all the xml files in the current folder
find . -name "*.xml" -exec grep "ERROR" /dev/null '{}' \+
Display all regular files under current directory tree ignoring files in './dir1' and './dir2' directories
find . -type f |sed '/.\/dir[12]\/[^/]*$/d'
create directory saxon_docs
mkdir saxon_docs
Login to "$HOST" and create file "$FILE_PATH" if it does not exist
ssh -q $HOST "[[ ! -f $FILE_PATH ]] && touch $FILE_PATH"
display the count of total number of text files in the folder /home/you which have been modified in the last 60*24 hours
find /home/you -iname "*.txt" -mtime -60 | wc -l
Replace ",," with ", ," in "$file" and display the "," delimited result as a table in "less" with a shift value of 5 and line numbers
cat "$file" | sed -e 's/,,/, ,/g' | column -s, -t | less -#5 -N -S
Find files matching pattern $2 in the $1 directory recursively and search them for text $3, where $1, $2, $3 are the command line arguments to the Bash script
find $1 -name "$2" | grep -v '/proc' | xargs grep -Hn "$3" {} \;
Open all .c files in the current directory tree in the vim editor
find . -name "*.c" -print | vim -
Find directories in the current directory tree that were modified within the last 24 hours and move them to /path/to/target-dir
find . -depth -type d -mtime 0 -exec mv -t /path/to/target-dir {} +
Finds recursively all folders named 'a' within current folder and removes only ones without files and another folders within.
find -type d -name a -exec rmdir {} \;
In a ssh session, set the variable 'user' to the last dot-separated number of the client's IP address.
export user=`env|grep -i SSH_CLIENT|cut -d' ' -f1|cut -d'.' -f4`
recursively change owner of the directory /tmp to the current user
sudo chown -R $USER ~/tmp
Find all xml files under current directory and archive them to .bz2 archives
find -name \*.xml -print0 | xargs -0 -n 1 -P 3 bzip2
Find all directories whose status were changed $FTIME days ago
find . -type d -ctime $FTIME
Find all .txt files except README.txt
find . -type f -name "*.txt" ! -name README.txt -print
Find all files/directories containing 'blah' in their names that were modified in less than 2 days ago uder current directory tree
find . -iname '*blah*' -mtime -2
Find all files/directories named 'query' (case insensitive) under current directory tree
find -iname "query"
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-"
Rename all *.jpg files to *.jpg$.jpg files under ../<dirname> directory by appending the parent directory name at the beginning of their names
find ../<dirname> -name '*.jpg' -exec sh -c 'mv "$0" "$(basename $)-${0%.JPG}$.jpg"' {} \;
Prints information about active network interfaces in system.
echo "$(ifconfig)"
Unsets shell function 'z'.
unset -f z
Creates temporary folder like '/tmp/tardir-XXXXXX' with 6-letter suffix and saves its path in 'tmpdir' variable.
tmpdir=$(mktemp -d /tmp/tardir-XXXXXX)
Display all lines in 'file' containing 'something', pausing for user input after each page.
grep something file | more
Show version information of the find utility
find -version
List all regular files from the current directory tree that were modified less than 60 minutes ago
find . -mmin -60 -type f | xargs ls -l
Save the number of records in the system hostname that contain numbers in variable "server_id"
server_id=`hostname | tr 'A-Za-z-.' ' ' | tr -d '[[:space:]]' | awk '{print NR}'`
Verbosely compresses all files on second and third depth level keeping original files in place.
bzip2 -kv */*
change the directory to the last found folder in the directory 'a'
cd `find a |sed '$!d'`
display all the files in the entire file system which are bigger than 10MB
find / -size +10000k
Save the full path of the current script into variable "THIS"
THIS=`readlink -f "${BASH_SOURCE[0]}" 2>/dev/null||echo $0`
simulate a full login of user builder
su -l builder
Go into the first directory whose name contains 1670
cd $
display list of all the hidden directories in the directory "/dir/to/search/"
find /dir/to/search -path '*/.*' -ls
Reread user's .profile configuration file.
source ~/.profile
Display various information about process currently taking the most CPU time.
top -b -n1 | head -8 | tail -1 | awk '{ printf "User: %s\nPID: %s\nCPU Usage: %s\nMEM Usage: %s\n", $2,$1,$9,$10 }'
run command "command" as user username with a full login simulation
su - username command
Get the list of files owned by <userid>
find . -user <userid>
List all files in the current directory tree larger than 1000 kb
find . -size +1000k
Print lines in "foo.txt" that are found only once
sort foo.txt | uniq
Print 2 lines of "123456789"
yes 123456789 | head -2
find all the files in the current directory and print them excluding those that have the name SCCS.
find . -print -o -name SCCS -prune
display ten files in the current directory
find | head
Find all files/directories named 'date' under /usr
find /usr -name date
Find all executable files under the current directory and below
find . -perm /a=x
search for all the files in the entire file system which have either suid or sgid bit enabled and find of diff of these files with the file "files.secure".
find / \ -print | diff - files.secure
find all the files in the current directory that have the word "bash" in their name
find . -name "*bash*"
Find files/directories writable by group or others under the /path directory
find /path -perm /g+w,o+w
Unsets 'history' shell option.
shopt -u -o history
split file input.txt into pieces per 1 line named output.NNNNN
split --lines=1 --suffix-length=5 input.txt output.
Show the value of variable "list", discarding consecutive duplicates and adding number of occurrences at the beginning of each line.
echo "$list" | uniq -c
Find all 'custlist*' files under current directory
find . -name custlist\*
Find all files/directories under current directory excluding the paths that match the POSIX extended regex ".*def/incoming.*|.*456/incoming.*"
find . -regex-type posix-extended -regex ".*def/incoming.*|.*456/incoming.*" -prune -o -print
recall the second argument from a previous command by pressing alt-shift-y
bind '"\eY": "\e2\e."'
Search the .java files from the /Applications/ directory tree for TODO lines
find /Applications/ -name "*.java" -print0 | xargs -0 grep -i "TODO"
display list of all the files in the /tmp folder
find /tmp/ -exec ls "{}" +
Print absolute path of java executable
readlink -f $(which java)
Save the user name of the current user to variable "me"
me="$"
display all the files only in the path "./sr*sc"
find . -path "./sr*sc"
Sort "file1.txt" and output the result to "file1.txt"
sort -o file1.txt file1.txt
ssh into localhost on port 10022
ssh -p 10022 localhost
Find files in the current directory tree whose names are of the form "cxx_data.txt" where xx is a number from 30 to 70
find . -regextype posix-egrep -regex '.\*c.\*'
replace "exp_to_find_for_replacement" with "exp_to_replace" for all the files in the current folder
find -name ‘*exp_to_find_in_folders*’ -exec rename “s/exp_to_find_for_replacement/exp_to_replace/” {} \;
Search the current directory and all of its sub-directory for any PDF files being careful to prevent the shell from expanding "*" before it's passed to find.
find . -name \*.pdf -print
Delete all lines matching "pattern to match" in "./infile" and make a backup with suffix ".bak"
sed -i.bak '/pattern to match/d' ./infile