nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Set the modification timestamp of file 'filename' to specified date/time.
touch -m --date="Wed Jun 12 14:00:00 IDT 2013" filename
create directory foo
mkdir -p foo
List any line in "f1" or "f2" which does not appear in the other and delete all tab characters in the output
comm -3 <(sort -un f1) <(sort -un f2) | tr -d '\t'
split file /usr/bin/gcc into pieces per 100000 lines
split -n 100000 /usr/bin/gcc
Set the variable "me" to the name of the running script.
me=`basename "$0"`
Sort "$file" and output the result to "$file"
sort -o $file $file
Use multiple -exec command in find . Find all .txt files & grep banna in .txt files .
find . -name "*.txt" -exec echo {} \; -exec grep banana {} \;
Counts the number of lines in *.php and *.inc files in a current folder and subfolders.
find . -name '*.php' -o -name '*.inc' | xargs wc -l
Recursively finds latest modified file in a directory
find . -type f -print0 | xargs -0 stat -f "%m %N" | sort -rn | head -1 | cut -f2- -d" "
List all environment variables (name and value) whose name either equals HOME or PATH, or starts with GO
env | grep '^\(GO\|HOME=\|PATH=\)'
Remove all directories called "test" from the current directory tree
find -path "*/test/*" -delete
Rename absolute path of symbolic link "dirln" to "dir2"
mv "$" dir2
Search directory tree `MyApp.app' for directories whose name is 'Headers' and delete them
find MyApp.app -name Headers -type d -delete
Ping all hosts in file "ips" twice
cat ips | xargs -i% ping -c 2 %
Count the number of lines in all ".txt" files
cat *.txt | wc -l
Search the `images' directory tree for regular files
find images/ -type f
find all the directories in current folder and delete them
find . -type d -delete
Print each logged in user's username and full name
finger -l | grep "Name:" | tr -s ' ' | cut -d " " -f 2,4- | sort | uniq
Print the list of files and directories of the /etc directory
find /etc/. ! -name . -prune
find all readable files
find / -readable
Print the current date followed by ' doing stuff'
echo $(date) doing stuff
Print all filenames in /usr/src except for those that are of the form '*,v' or '.*,v'
find /usr/src -not \ '{}' \; -print
Search the /path directory tree for files that do not have a valid user or group
find /path -nouser -or -nogroup
Removes trailing and starting newlines from file
tac file | sed -e '/./,$!d' | tac | sed -e '/./,$!d'
Recursively change the owner of all "*.txt" files under "/mydir" to "root"
find /mydir -type f -name "*.txt" -execdir chown root {} ';'
Unzip every ".gz" file in the current directory
gunzip *.gz
Recursively copy all (non-hidden) files and directories in current dir except "foo" to location specified by variable "other"
rsync --recursive --exclude 'foo' * "$other"
Read a line from standard input into variable "SSHPASS" with prompt "Password: " and without echoing the input
read -p "Password: " -s SSHPASS
Find all files/directories with '.js' extension under current directory tree excluding paths that contain the directory './directory'
find -name "*.js" -not -path "./directory/*"
Replace ",," with ", ," twice in "data.csv" and display the "," delimited result as a table
sed 's/,,/, ,/g;s/,,/, ,/g' data.csv | column -s, -t
find all the html, javascript and text files in the current folder
find . -type f -name "*.htm*" -o -name "*.js*" -o -name "*.txt"
SSH into "localhost" with forced pseudo-terminal allocation, execute "$heredoc", and save the output to variable "REL_DIR"
REL_DIR="$(ssh -t localhost "$heredoc")"
Find *.conf files/directories only upto 1 level down under /etc directory and show a few lines of output from the end
find /etc -maxdepth 1 -name "*.conf" | tail
Make directories and parents as needed to "${raw_folder}" and "${split_folder}"
mkdir -p ${raw_folder} ${split_folder}
remove all the "core" files in the current folder which have not been changed in the last 4 days.
find . -name core -ctime +4 -exec /bin/rm -f {} \;
Check that the master ssh connection "officefirewall" is running
ssh -O check officefirewall
Find all files/directories under current directory
find | xargs
Search the current directory recursively for regular files modified 2 days ago
find . type -f -mtime 2
Find all regular files under and below /home/admin/public_html/, and change their permissions to 644
find . /home/admin/public_html/ -type f -exec chmod 644 {} \;
Replace all spaces with underscores in directory paths under current directory.
find -name "* *" -type d | rename 's/ /_/g'
Find all regular files under test directory
find test -type f
Request IP address of 'myip.opendns.com' from name server 'resolver1.opendns.com'
dig +short myip.opendns.com @resolver1.opendns.com
Copy the owner and group of "oldfile" to "newfile"
chown --reference=oldfile newfile
Prints current directory name
pwd | awk -F/ '{print $NF}'
Find all *.plist files/directories under current directory
find . -name \*.plist
List the regular files of the current directory tree that contain string "texthere"
find -type f -exec grep -l "texthere" {} +
Find all directories under current directory and set read & execute permission for group and other for these files
find . -type d -print0 | xargs -0 chmod go+rx
For every cron job with a comment "change-enabled" at the end of its crontab entry, change the scheduled hour to 7.
crontab -l | sed -re '/# *change-enabled *$/s/^ [^ ]+/\1 7/' | crontab -
count lines of C or C++ or Obj-C or Java code under the current directory
find . \ -print0 | xargs -0 wc
display the manual page of find
man find
Find the "erl" executable in $PATH and read the "RELEASES" file to extract the erlang release number
awk -F, 'NR==1 {gsub(/"/,"",$3);print $3}' "$(dirname $(readlink -f $(which erl)))/../releases/RELEASES"
Recursively add read and execute permissions to all files and folders in "directory"
chmod -R +xr directory
Print the list of all directories under the current directory and below
find ./ -type d -print
renames all ".htm" files to ".html" files
find . -name "*.htm" -exec mv '{}' '{}l' \;
find all the directories with the name "uploads" in current folder
find . -type d -name 'uploads'
display list of all the hidden files in the directory "/dir/to/search/"
find /dir/to/search/ -name ".*" -ls
search for all the regular files in the folder /home which have the permission 077
find /home -type f -perm 0777 -print
Update timestamps of all files in entire filesystem which are not newer than /tmp/timestamp
find / ! -newer /tmp/timestamp -exec touch {} \;
delete all the tmp files in the /tmp folder
find /tmp -name "*.tmp" | xargs rm
Display the contents of "myfile" located in the current directory.
cat myfile
find all the text files in the home directory
find ~/ -name '*.txt'
Find all files in current directory that were modified less than 1 day ago excluding hidden files and archive them and put the output into the variable file_changed
file_changed=$(find . -depth \( -wholename \./\.\* \) -prune -o -mtime -1 -print | cpio -oav)
Save the short system host name to variable "hostname"
hostname=`hostname -s`
Find all files named "filename"
find -name "filename"
create a zip file of all the files in some directory
find $directory -type -f -execdir zip -j $ZipFileName {}\;
Recursively finds all "*.pas" and "*.dfm" files and prints strings with "searchtext" ignoring text distinctions, suppressing error messages, highlighting found patterns and preceding each found string with file name and string number.
find . -type f \( -name "*.pas" -o -name "*.dfm" \) -print0 | xargs --null grep --with-filename --line-number --no-messages --color --ignore-case "searchtext"
Find SGID files
find / -perm +2000
Find all *.py files/directories under current directory
find . -name \*.py -print
Find all regular files in and below the home directory that have been modified in the last 90 minutes
find ~ -type f -mmin -90
Find all *.jpg files under current directory
find . -name *.jpg
Search the current directory tree for regular files omitting directory `omit-directory'
find . -name omit-directory -prune -o -type f
Recursively delete all files/folders named '.svn' in a current folder.
find . -name .svn -delete
Remove all .txt files in and below the current directory
find . -name "*.txt" -exec rm {} \;
display all the regular/normal files in the current directory
find . -type f
find all files in the file system with the permissions 777 and having the word "filename" in their name.
find / -perm 777 -iname "filename"
Search for files greater than 20MB in the entire file system and display the path and file size
find / -type f -size +20M -exec ls -lh {} \; | awk '{ print $NF ": " $5 }'
Report file systems inode usage.
df -i
Search the system for regular files whose names are "filename" ignoring the case
find / -type f -iname "filename"
Search all files & directoy from root directory which are greater then 100M and delete them .
find / -size +100M -exec rm -rf {} \;
Find all dir* files/directories under parent
find parent -name dir*
Search the current directory tree for the files with extension "trc" and remove them if they are more than three days old
find . -name "*.trc" -ctime +3 -exec rm {} \;
Save the first "." separated field of the system host name to variable "HOSTZ"
HOSTZ=$
Print output of 'script -q /dev/null ./a' to standard output and "output.txt"
script -q /dev/null ./a | tee output.txt
Output the specified path removing all containing directories and the .txt suffix, in this case "filename".
basename /path/to/dir/filename.txt .txt
Fiind and remove multiple files such as *.mp3 or *.txt
find . -type f -name "*.txt" -exec rm -f {} \;
display a long list of all the jpg files in the home folder
find ~ -iname '*.jpg' -exec ls {} \;
Display the last slash-separated part of path, in this case "example".
basename /usr/local/svn/repos/example
Get the disk space used by all *.txt (case insensitive) files/directories under current directory
find . -name "*.txt" -print0 |xargs -0 du -ch | tail -n1
Change directory to the output of command '~/marker.sh go "$@"'
cd $
Print multiline text "ONBOOT=\"YES\"\nIPADDR=10.42.84.168\nPREFIX=24" to the terminal, replacing '\n' with newline symbol, and append that text to file /etc/sysconfig/network-scripts/ifcfg-eth4 as root user.
echo -e "ONBOOT=\"YES\"\nIPADDR=10.42.84.168\nPREFIX=24" | sudo tee -a /etc/sysconfig/network-scripts/ifcfg-eth4
count all the regular files that are present in a directory
find . -type f | wc -l
Print a 2 byte hexadecimal value, printable character, and octal value of "$1"
echo "$1" | od -xcb
Print information of the root mount point
mount -v | grep " on / "
Make directory "/var/svn"
sudo mkdir /var/svn
Move all hidden files in "/path/subfolder/" to "/path/"
mv /path/subfolder/.* /path/
Split "infile" into 2 files of about equal size
split -n2 infile
Find all directories named '.texturedata' under '/path/to/look/in/' directory tree
find /path/to/look/in/ -type d -name '.texturedata'
Find all files under /path and below writable by `group' and `other'
find /path -perm -022
Find files and directories modified in last 24 hours
find . -mtime 1
Recursively copy all files and directories matching "*ela*L1*TE*" in localhost's directory /tdggendska10/vig-preview-dmz-prod/docs/sbo/pdf/ to /var/www/html/sbo/2010/teacher/ela/level1 on localhost connecting as ssh user "dalvarado", in batch mode preserving file permissions and timestamps, and without displaying progress information.
scp -Bpqr /tdggendska10/vig-preview-dmz-prod/docs/sbo/pdf/*ela*L1*TE* dalvarado@localhost:/var/www/html/sbo/2010/teacher/ela/level1