nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Locate symlinks in directory trees lpi104-6 and research/lpi104-6
find lpi104-6 research/lpi104-6 -type l
Prints directory where the executing script ($0) is located.
$(dirname $0)
Find all files, starting from / but ignoring removable media, whose names end with ".rpm"
find / -xdev -name "*.rpm"
List the entire cron job list of user "apache".
crontab -u apache -l
Execute "ls -l" every 2 seconds
watch ls -l
search for files with the name "temp" in the /usr folder
find /usr -name temp -print
Merge lines whose first comma-separated field in file 'in1' also appears as a first comma-separated in file 'in2' - both files must be sorted, and the output format of each line will be: first field of in1, second field of in2, and third field of in2.
join -t, -o 1.1,1.2,2.3 in1 in2
search for all the regular/normal files with the name "access.log" in the folder /var/www which are bigger than 100MB
find /var/www -type f -name «access.log*» -size +100M
find all c, cpp files in current folder
find -regex '.*\.\'
Save the canonical path of "/usr/bin/java" with "/bin/java" removed to variable "JAVA_HOME"
JAVA_HOME=$
List all files in the current directory tree that were last modified on the 3rd of March, 2010 or later
find -newermt "mar 03, 2010" -ls
Search for the string 'git' in all the files under current directory tree without traversing into '.git' folder and excluding files that have 'git' in their names
find . -path ./.git -prune -o -not -name '*git*' -print |grep git
find files in the current directory and sub-directories, that were accessed within last hour
find -amin -60
Counts the number of lines in only text files in a git repository.
git ls-files | xargs file | grep "ASCII" | cut -d : -f 1 | xargs wc -l
Find files and directories modified within the last 7 days
find . -mtime -7
force remove all the regular/normal files which begin with sess in the temp folder
find /tmp -type f -name sess* -exec rm -f {} \;
Print true directory name of the current directory
readlink `pwd`
List all aliencoders.[0-9]+ files/directories under /home/jassi/ directory
find /home/jassi/ -name "aliencoders.[0-9]+" | xargs ls -lrt | awk print '$9'
find the md5 sum of all the regular files in multiple folders and display them in sorted order
find teste1 teste2 -type f -exec md5 -r {} \; | sort
View manual page of find utility
man find
Shows status of a shell option 'dotglob'.
shopt dotglob
Find all regular .mp3 files larger than 10M and delete them
find / -type f -name *.mp3 -size +10M -exec rm {} \;
Make a copy of the entire contents of dir1 in the Pictures directory located in the user's home directory.
cp -r dir1/ ~/Pictures/
create directory destdir
mkdir destdir
Find all .gif and .jpg files in the /var/www directory tree
find /var/www -name *.gif -o -name *.jpg
Print only first line of 'file' content, formatted as 29-symbol wide column, regarding space symbol as a word separator
cat file | fold -s -w29 | head -1
Replace "firstWord" with "newFirstWord", "secondWord" with "newSecondWord", "thirdWord" with "newThirdWord" in all XML files in the current directory tree
find -name "*.xml" -exec sed -s --in-place=.bak -e 's/firstWord/newFirstWord/g;s/secondWord/newSecondWord/g;s/thirdWord/newThirdWord/g' {} \;
Read a line from standard input and save each word in the bash array variable "arr"
read -a arr
Look for *log files in directories at most three levels down the directory tree
find / -maxdepth 3 -name "*log"
Set variable 'file' to the base name of first argument to script or function, that is the part following the last slash.
file=`basename "$1"`
search for all the files in the folder /usr/bin which have not been accessed in the last 100*24 hours
find /usr/bin -type f -atime +100
Find all files matching "abc*" in the current directory and append a column with "OK"
find . -name 'abc*' -exec echo {}' OK' \; | column -t
Search the current directory for all regular files executable by 'user', 'group', and 'others'
find . -maxdepth 1 -type f -perm -ugo=x
Find all files/directories with 'my key phrase' in their names under current directory, search for 'my key phrase' in all files under current directory and print a sorted and unique list of output
{ find . -name '*my key phrase*'; grep -rl 'my key phrase' .; } | sort -u
Prints all NS servers of domain google.com.
dig google.com ns | awk 'p{print $5}/^;; ANSWER SECTION:$/{p=1}/^$/{p=0}'
find all files in the current folder which have been accessed in the last 30 minutes
find . -amin -30
Print which files differ in "PATH1/" and "PATH2/" recursively excluding any files that match any pattern in "file1"
diff PATH1/ PATH2/ -rq -X file1
Find all .less files in the current directory tree
find . -name *.less
display all the directories in the folder master-
find master -type d | sort
Print the current date followed by ' doing stuff'
echo $ doing stuff
Add group write permission to all files and directories in the current directory including hidden files and excluding ".."
chmod g+w .[^.]* ..?*
display the html, javascript and text files in the current folder
find . -type f \ -print0 | xargs -0 -n1 echo
Recursively changes group ownership of everything in 'files' to 'apache_user'.
chgrp -R apache_user files
Prints year-month-date format for given time
date -d "yesterday 13:00" '+%Y-%m-%d'
Find all filenames ending with .c in the /usr directory tree
find /usr -name "*.c"
Find all files under $musicdir directory
find "$musicdir" -type f -print
Adjust the timestamp of file $filename by subtracting 2 hours from it
touch -d "$ - 2 hours" "$filename"
Send SIGTERM to all processes using TCP port 6000 on the system using root account.
sudo kill -15 $
recursively change owner of the directory and all files into it to user nobody
chown -R nobody upload_directory
Search the system for the file “testfile.txt” ignoring the case
find / -iname "testfile.txt"
Save the absolute path of "$path" to variable "fullpath"
fullpath=`readlink -f "$path"`
Merge lines whose first comma-separated field in file 'in1' also appears as a first comma-separated in file 'in2', also outputting unmatched lines from 'in2' - both files must be sorted, and the output format of each line will be: first field of in1, second field of in2, and third field of in2.
join -t, -o 1.1,1.2,2.3 -a1 in1 in2
Connect to port 1234 of specified IP address or hostname as ssh user "user", and copy all visible files in /var/www/mywebsite/dumps/ on this host to local directory /myNewPathOnCurrentLocalMachine - this directory must already exist on local host.
scp -P 1234 user@[ip address or host name]:/var/www/mywebsite/dumps/* /var/www/myNewPathOnCurrentLocalMachine
Creae a tarball 'files.tar.gz' containing all regular files under current directory tree that are newer than 2013-12-04 and older than 2013-12-05
find . -type f -name "*" -newermt 2013-12-04 ! -newermt 2013-12-05 | xargs -I {} tar -czvf files.tar.gz {}
Make directories for each line in "folder_list.txt"
cat folder_list.txt | xargs mkdir
Archive the directory structure under current directory into dirstructure.tar
find . -type d -print0 | tar cf dirstructure.tar --null --files-from - --no-recursion
Prints lines count in each *.c file of a current folder and total count.
wc -l *.c
Recursively findsfiles with text pattern in current folder, ingnoring case differences, prefixes each matched line with number in file and suppresses error messages about nonexistent or unreadable files.
grep -insr "pattern" *
find all the directories in the different folders excluding search in the sub directories and create these folders in the current directory
find /media/New\ Volume/bhajans -maxdepth 1 -type d | xargs -0 mkdir -p
Change permissions to u=rw,g=r,o= for all files in the current directory tree
find . -type f -exec chmod u=rw,g=r,o= '{}' \;
Saves index number of file 'script.sh' in the 'inode' variable.
inode=`ls -i ./script.sh | cut -d" " -f1`
display all the files in the entire file system which begin with "apache-tomcat"
find / -name "apache-tomcat*"
Find all files under current directory without descending into .snapshot directory that were modified in last 24 hours with null character as the delimiter
find . -name .snapshot -prune -o \( -type f -mtime 0 -print0 \)
Split "/tmp/files" into files of at most 1000 lines each
split /tmp/files
get the root access
sudo su
Check all .txt files whether they contain "needle"
find . -type f -iname "*.txt" -print | xargs grep "needle"
Search for the case insensitive regex expanded by $2 in all files named $1 (to be expanded) under current directory
find . -name "$1" -type f -exec grep -i "$2" '{}' \;
Move all the .c files from the current directory tree to temp/
find . -name "*.c" -print0 | xargs -0 -n1 -I '{}' mv '{}' temp
Display differences between /tmp/test1 and /tmp/test2 side-by-side.
diff -y /tmp/test1 /tmp/test2
copy all files which do not have execute permission to another folder
cp `find -perm -111 -type f` /usr/local/bin
find all 'js' suffix files exclue the path *exclude/this/dir*' under current dirctory
find . -name '*.js' -not -path '*exclude/this/dir*'
Find files containing string "#!/bin/ksh" and append their names and matching strings to /tmp/allfiles
find . -type f -print | xargs /usr/bin/grep -il 'bin/ksh' | tee /tmp/allfiles
Prints sorted list of logged in users.
w -h | cut -d' ' -f1 | sort | uniq
Return 0 if file system is mounted on '/full/path'
df /full/path | grep -q /full/path
Search the `research' directory and one level below for directories that are not owned by group `ian'
find -L research -maxdepth 2 -type d ! -group ian
find all the files in the entire file system which have been modified in the last 5 days
find / -mtime -5 -print
Display all files in the folder home which are owned by the group test.
find /home -group test
Create new crontab set including $job and only jobs from current crontab that don`t contain $command
cat <(fgrep -i -v "$command" <) < | crontab -
get year-month-day hour:minute:second from date
date +%Y-%m-%d:%H:%M:%S
Find writable regular files omitting those that contain sites/default/files in their names
find . -type f -writable | grep -v sites/default/files
Prints groups list that current user belongs to.
groups //take a look at the groups and see
Search decompressed "filename.gz" for case-insensitive "user-user"
zcat filename.gz | grep -i user-user
Remove what follows the forth occurrence of the character ":" in any field which contains it
sed -r 's/({3}):[^ \t]*/\1/g' file | column -t
display a long list of all the files in the directory "/mydir" which have not been modified in the last 20*24 hours or which have not been accessed in the last 40*24 hours
find /mydir \(-mtime +20 -o -atime +40\) -exec ls -l {} \;
create a tar ball of all the jpg and png images in the current folder
find . \( -iname "*.png" -o -iname "*.jpg" \) -print -exec tar -rf images.tar {} \;
Search case insensitively for 'facebook', 'xing', 'linkedin', ''googleplus' in file 'access-log.txt', extract the matched part, sort them and print them by sorting them in asending order of the number of repeated lines
grep -ioh "facebook\|xing\|linkedin\|googleplus" access-log.txt | sort | uniq -c | sort -n
Print the host name
hostname
display all directories in the folder "/myfiles"
find /myfiles -type d
Print only the number of lines in file "$f"
wc -l $f | tr -s ' ' | cut -d ' ' -f 1
find all files ending with "js.compiled" in current folder and rename them.
find . -name "*.js.compiled" -exec rename -v 's/\.compiled$//' {} +
Print every two lines in "file" on a single line separated by a space
cat file | paste -d\ - - -
display all normal/regular files in current folder
find . -type f
Print "huzzah" if directory "/some/dir" is empty
find /some/dir/ -maxdepth 0 -empty -exec echo "huzzah" \;
Remove all files under current directory
find -exec rm '{}' +
Change onwer of "file" to "user_name"
chown user_name file
Merge each non-blank line of standard input into a single comma separated line
grep -v '^$' | paste -s -d"," -
Search the *.c files residing in the current directory tree for string "blash"
find . -name *.c -exec grep -n -e blash {} \;
search for all the files in the folder /data/images which are modified after /tmp/foo
find /data/images -newer /tmp/foo
Print content of 'filename' file, showing all non-printing characters and displaying $ at the end of each line.
cat -v -e filename
Unsets all environment variables with 'G4' in name.
unset `printenv |grep G4 |awk 'BEGIN{FS="=";}{printf;}'`