nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Save the first word of the first difference in ".dir_list_2" compared to ".dir_list_1" into variable "extract_dir"
extract_dir=$
Replace the occurrences of "HOGE" with "MOGA" once per each line of the .yaml files from the current directory tree
find . -type f -name "*.yaml" -print0 | xargs -0 sed -i -e "s/HOGE/MOGA/"
show all directories in the current folder excluding those that are present only in the paths ./media, ./images and ./backups
find . -path './media' -prune -o -path './images' -prune -o -path './backups' -prune -o -print
Create an empty index.html, or update its timestamp if it already exists.
touch index.html
display all the files in the current folder except those whose name is "PERSONAL"
find . -name PERSONAL -prune -o -print
Find all filename.* files/directories under /root/directory/to/search
find /root/directory/to/search -name 'filename.*'
Find all directories in the /data1/realtime directory tree that were last modified more than 5 minutes ago but less than 60 minutes ago
find /data1/realtime -mmin -60 -mmin +5 -type d
Pushes current folder to the directory stack.
pushd $PWD
set alias "te" for command 'tail -f /var/log/apache2/error_log | perl -ne '\''...'\'''
alias te='tail -f /var/log/apache2/error_log | perl -ne '\''...'\'''
Print git branch currently checked out in a working directory.
git status | head -1 | cut -d ' ' -f 3
Find files and directories in the /tmp/ tree that contain spaces in their names and replace those spaces with underscores
find /tmp/ -depth -name "* *" -execdir rename 's/ /_/g' "{}" \;
Delete all empty subdirectories in and below directory/
find directory -mindepth 1 -type d -empty -delete
Find all *.txt, *.html files under /basedir that match the case insensitive pattern *company* in their names
find /basedir/ \( -iname '*company*' -and \ \) -print0
Print "This is a sentence." by replacing all consecutive space characters with a single newline character
echo "This is a sentence." | tr -s " " "\012"
Change directory to the current user's home directory
cd /home/`whoami`
find regular files under the current directory and execute an md5sum command on each one
find -type f -exec md5sum {} +
Find all files/directories under '/usr/local' containing 'blast' in their names
find /usr/local -iname "*blast*"
Create all directories in the path specified by variable $javaUsrLib as super user
sudo mkdir -p $javaUsrLib
Set environment variables using assignments are listed in '.env' file and run 'rails' command with defined environment
env $(cat .env | xargs) rails
Find all files in current directory excluding hidden files and put the output into full_backup_dir variable
full_backup_dir=$(find . -depth '(' -wholename './.*' ')' -prune -o -print)
Print the characters in $b that match with any character in $a without printing any whitespace in-between
echo "$b" | grep --only-matching "[$a]" | xargs | tr --delete ' '
Print the current working directory without a trailing newline
echo -n $(pwd)
List all .c and .h files in the current directory tree that contain "thing"
find . -name '*.[ch]' -print0 | xargs -r -0 grep -l thing
Search the "test1" directory recursively for regular files named "textfile.txt"
find test1 -type f -name 'textfile.txt' -print
print top 10 largest files and directories
du -a . | sort -nr | head
find in the file system for the directories with the name "httpdocs" discard all the errors
find / -type d -name httpdocs 2> /dev/null
Find writable regular files omitting those that contain sites/default/files in their names
find . -type f -writable | grep -v sites/default/files
display all files which have been modified between two dates in current folder
find . -type f -newermt "2014-01-01" ! -newermt "2014-06-01"
list all names of the aliases
alias | awk '/^alias /{print substr($2,1,index-1)}'
Find all *shp* files/directories under current directory and move them to ../shp_all/
find . -name "*shp*" -exec mv {} ../shp_all/ \;
Search /root/directory/to/search recursively for the files matching pattern 'filename.*'
find /root/directory/to/search -name 'filename.*'
The command runs all the directories (-type d) found in the $LOGDIR directory wherein a file's data has been modified within the last 24 hours (-mtime +0) and compresses them (compress -r {}) to save disk space.
find $LOGDIR -type d -mtime +0 -exec compress -r {} \;
Search the current directory tree for all .java files that were last modified at least 7 days ago
find . -name '*.java' -mtime +7 -print
Gets list of IP addresses of all network interfaces.
ifconfig | awk -F"[ :]+" '/inet addr/ && !/127.0/ {print $4}'
remove all text files from the current folder. Print0 is used to handle files whose names have only spaces or those files which have newlines in their names
find -name "*.txt" -print0 | xargs -0 rm
Print the list of files from the "/zu/durchsuchender/Ordner" directory tree whose names begin with "beispieldatei" and which contain string "Beispielinhalt"
find "/zu/durchsuchender/Ordner" -name "beispieldatei*" -print0 | xargs -0 grep -l "Beispielinhalt"
find all the xml files in current folder and which are present in the pattern list file "/tmp/a"
find . -name "*.xml" -exec grep -HFf /tmp/a {} \;
find all the directories in the current folder which have been modified in 24 hours and move them to the folder /path/to/target-dir
find . -type d -mtime -0 -exec mv -t /path/to/target-dir {} +
Move all directories in the current directory tree that have been modified in the last day to "/path/to/target-dir"
find . -type d -mtime -0 -print0 | xargs -0 mv -t /path/to/target-dir
List all files in a current folder, separating names with comma
ls -1 | tr '\n' ','
Find all files under current directory and search for 'something' in those files
find . -exec grep something {} +
Shows status of a shell option 'nullglob'.
shopt nullglob
Print the file 'text1;text2;text3' replacing each space with a newline
cat "text1;text2;text3" | sed -e 's/ /\n/g'
Search the /myfiles directory tree for regular files with at least these permissions: 647
find /myfiles -type f -perm -647
Report file systems disk usage in 1GB blocks.
df -BG
Find all *FooBar* files/directories under current directory and copy them to ~/foo/bar
find . -name '*FoooBar*' | sed 's/.*/"&"/' | xargs cp ~/foo/bar
Print full path of command "programname"
which programname
set alias ":" for command 'xargs -I{}'
alias :='xargs -I{}'
create directory subdirectory
mkdir subdirectory
Display the last slash-separated part of path, in this case "example".
basename /usr/local/svn/repos/example
Find regular files modified within the last 7 days
find . -mtime -7 -type f
Find files with 002 permission in entire file system with the null character as the delimiter
find / -type f -perm -002 -print0
Execute Shell script with find comamnd
find -maxdepth 0 -name "*.sh" -exec ./lastline.sh {} \;
Report file systems disk space usage pretty formatted.
df -Ph | perl -ne 'chomp; printf "\n%-40s %8s %8s %8s %8s %-20s", split / +/, $_, 6 ; '
Find all regular *.css files
find . -type f -name "*.css"
Find regular files matching pattern "*oraenv*" and excecute the "file" utility for each of them
find . -name "*oraenv*" -type f -exec file {} \;
Unzip "large.csv.gz" and save every 1000 lines into a file with prefix "xxx"
gzcat large.csv.gz | split -l 1000 - xxx
Make directories "~/foo/bar/baz", "~/foo/bar/bif", and "~/foo/boo/bang" as needed
mkdir -p ~/foo/bar/baz ~/foo/bar/bif ~/foo/boo/bang
display all the files in the file system which belong to the group lighttpd
find / -group lighttpd -print
Removes all empty folders that ends with any-cased '*.bak' under '/Users/' path.
find /Users -type d -iname '*.bak' -print0 | xargs -0 rmdir
find all files in the current folder which are of size 0 bytes.
find . -type f -size 0b
Search directory tree `MyApp.app' for directories whose name is 'Headers' and delete them in an optimized way
find -d MyApp.app -name Headers -type d -exec rm -rf {} +
Find the password file between sub-directory level 2 and 4.
find -mindepth 3 -maxdepth 5 -name passw
Find all files/directories with '.c' or '.h' extension under current directory tree and search for the regex expanded by the variable $i and show the output by paging through one screenful at a time
find . -name '*.[ch]' -exec grep $i {} | less
Saves printed calendar for $month, $year in positional variables.
set `cal $month $year`
Send a single ping request with a TTL of 1 to "192.168.1.1"
ping -c 1 -t 1 192.168.1.1
display all the html files in the current folder that have been modified exactly 7*24 hours ago
find . -mtime 7 -name "*.html" -print
display all the trace files (".trc") from the folder $DBA/$ORACLE_SID/bdump/ which have not been accessed in the last 7*24 hours
find $DBA/$ORACLE_SID/bdump/*.trc -mtime +7
Find all directories under current directory excluding directories that start with a . in their names
find . -type d -a ! -name '.?*' -o -name '.?*' -a ! -prune
Find all identical files in the HOME directory and subdirectories and tell if there are hard links
find $HOME -type f | samefile -r
List all files/directories under current directory matching the posix-egrep type regex ".+\.(c|cpp|h)$" in their names
find . -regextype posix-egrep -regex ".+\.(c|cpp|h)$" | xargs -n 1 ls
Convert relative symbolic link "$link" to absolute symbolic link
ln -sf "$" "$link"
Delete all in the current directory tree
find . -delete
Create a temporary directory and go into it.
tmpdir=$ && cd $tmpdir
Reports count of processors in system.
grep '^core id' /proc/cpuinfo |sort -u|wc -l
Find all files/directories under 'A' directory tree excluding directory 'A/a' and all of it's contents
find A \! -path "A/a/*" -a \! -path "A/a"
Force create a hard link in "/usr/local/bin" to "findpdftext"
sudo ln -f "findpdftext" /usr/local/bin
Disables overwriting existing files
set -o noclobber
show all the files in the entire file system which are bigger than 100MB
find / -size +100M
make directory "/etc/cron.15sec"
mkdir /etc/cron.15sec
Search the current directory tree for files and directories with permissions 775
find . -perm 775 -print
Search for files in the current user's home directory and below for files that have not been accessed for more than 100 days and ask the user for permission to delete each file, one by one.
find ~/ -atime +100 -exec rm -i {} \;
Print "I am USER and the program named ls is in LS_PATH" where "USER" is the current user's user name and "LS_PATH" is the full path of the command "ls"
echo I am $ and the program named ls is in $.
search for a word in all the fies in the current folder
find . -type f -exec grep some_string {} \;
Find all broken symlinks under current directory
find . -xtype l
Print the base name of the current working directory
pwd | xargs basename
Search for 'pattern' in file 'file' and print the matched lines by separating them with spaces instead of newlines
grep pattern file | tr '\n' ' '
Clean directories and subdirectories of the temporary files generated during normal use
find . \( -name a.out -o -name '*.o' -o -name 'core' \) -exec rm {} \;
change permission of all the files in the entire file system which have permissions 777.
find / -type f -perm 0777 -print -exec chmod 644 {} \;
Kill a running screen session
screen -X -S SCREENID kill
Print last four bytes of string '0a.00.1 usb controller some text device 4dc9'
echo 0a.00.1 usb controller some text device 4dc9 | rev | cut -b1-4 | rev
find all the files in the folder "/u/bill" which have been accessed in the last 2-6 minutes
find /u/bill -amin +2 -amin -6
Search for the system host name in "/etc/hosts" and print the IP address in the first awk field
more /etc/hosts | grep `hostname` | awk '{print $1}'
Recursively set all permissions under "/whatever/your/directory/is" to 755
sudo chmod 755 -R /whatever/your/directory/is
Merge data in file1 and file2 where second field is common in both files
join -j2 <(sort -k2 file1) <(sort -k2 file2)
search for all the mp3 files in the folder /home/you which have been accessed 24 ago
find /home/you -iname “*.mp3” -atime 01 -type -f
find all jpg images starting with image in the folder "dir" and give them as input to the script, script.ksh
find dir -name image\*.jpg -exec /bin/ksh script.ksh {} \;
Change permissions to u=rwx,g=rx,o= for all directories in the current directory tree
find . -type d -exec chmod u=rwx,g=rx,o= '{}' \;
find all the files in the entire file system that start with top
find / -name 'top*'
Prints process tree of a process having id $ID with parent processes.
pstree -s $ID