zsh example using a 'for' loop and arithmetic expression: files matching the pattern '*.jpg' are renamed with a 3 digit prefix, keeping the previous filename and suffix. Show Sample Output
Requires zsh. You might also do the following: for (*.txt) mv $i ${i/.txt/.csv} or I imagine the following will work in bash: for i in "*.txt" ; do mv $i ${i/.txt/.csv} ; done
example of using zsh extended globbing
zsh: add leading zero ... altogether pointless, as there can only be a maximum of 10 'single digit' files, and so a maximum of 10 files the command can act on. Padding further zeros will produce '0010', '001' and so break sequance. The only proper method is to itterate the numbers like so: i=1; for f (*) zmv $f '${(l:3::0:)$((++i))}'.txt but this has the unfortunate side effect of incrementing the values by 1 ... which may not be desirable. Show Sample Output
replace (any number of) space[s] with underscore. Show Sample Output
example of zsh globbing and glob qualifiers: "**/*" recursive (.m0) '.' = regular file, 'm0' = modified zero days (so, today).
zsh: "**/*" = recursive "(.Lm+100)" "." = files, "L" = filesize glob qualifier, "m" = mb, "+100" = 100
A method for aquiring the ip address using zsh. If you prefer the use of iproute2 (which, frankly, you should) then the following should provide the same (ip outputs CIDR addresses): print ${$(ip -o -4 a s eth0)[4]} we could also pass a qualifier to take only the IP and not the (CIDR) mask print ${$(ip -o -4 a s eth0)[4]:h} or, similarly, for the MAC address: print ${$(ip l l eth0)[15]}
example of the use of zsh glob qualifiers: "@" = the symlink qualifier "[1]" = first element :t = remove leading path components, leaving the tail
zsh globbing and glob qualifier: '**/*' = recursive om = ouput by modification (last access) [1,20] = twenty files. The '-t' switch is provided to ls so that the files are ordered with the most recent at the top. For a more 'find' like output the following can be used. print -rl **/*(om[1,20])
Example of using zsh glob qualifier ... "." = files "f:" = files with access rights matching: o+w = other plus write
Example of zsh globbing and parameter expansion.
(*.*)(.*) ... the pattern we want to act on, a period followed by a string and then period, we split the pattern into two sections which will become $1, the first part of the match, and $2, second
{1//./_}$2 ... the parameter expansion for $1 with a string substitution, followed by the match $2, the second part of the pattern.
Prints an easy-to-copy color code for each color. Show Sample Output
Like in bash.
"$PWD" (in quotes) accounts for spaces and other characters normally escaped in file or folder names
MacOS Solution due to lack of pidof command and procfs on MacOS Kernel. Show Sample Output
The “predictive capture” feature of Sony's Xperia camera app hides the date stamp deeply inside the filename. This command adds another date stamp at the beginning of the filename. Show Sample Output
For each *.jpg or *.JPG file in the current directory, extract the date the photo was taken from its EXIF metadata. Then replace the date stamp, which is assumed to exist in the filename, by the date the photo was taken. A trick from https://unix.stackexchange.com/a/9256 is used to split the date into its components. Show Sample Output
This version won't reconnect if you exit the ssh connection with a non-zero exit code. ConnectTimeout and sleep values knobs for how long to wait for each retry.
Often times you run a command in the terminal and you don't realize it's going to take forever. You can open a new terminal, but you lose the local history of the suspended one. You can stop the running command using , but that may produce undesirable side-effects. suspends the job, and (assuming you have no other jobs running in the background) %1 resumes it. Appending & tells it to run in the background. You now have a job running concurrently with your terminal. Note this will still print any output to the same terminal you're working on. Tested on zsh and bash. Show Sample Output
zsh has a powerful correction mechanism. If you type a command in the wrong way it suggests corrections. What happend here is that dir is an unknown command and zsh suggests gdir, while maybe ls was what you wanted. If you want to execute gdir hit y (yes) If you want to try to execute dir anyway hit n (no) If you want to execute completely different spelt command like ls hit a (abort) and type your command If you want to execute a similar spelt commant like udir hit e (edit) and edit your command. Show Sample Output
This attempts to load a Perl Module (-M flag) and use version 9999, since no module has a version this high, Perl exits either a) telling you the version of the module installed or b) tells you it can't find the module. Show Sample Output
When you use the "exit" command in a Linux terminal window, it not only closes the terminal window itself but also the terminal emulator app, such as GNOME Terminal or Konsole, that it belongs to. If you use the "exit" command on macOS, however, Terminal.app still shows a dot below its Dock icon and is still running in the background. This alias, when entered into ~/.zshrc, overrides this behavior.
See smbstatus Output within a 5 second interval (for monitoring smb access)
commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for: