Locate broken symlinks in the current directory. Also useful, to remove broken links:
find . -type l ! -exec test -e {} \; -print0 | xargs -0 rm
I often need to know of my directory in the PATH, which one DOES NOT exist. This command answers that question * This command uses only bash's built-in commands * The parentheses spawn a new sub shell to prevent the modification of the IFS (input field separator) variable in the current shell
I often use "vim -p" to open in tabs rather than buffers.
#Usage: watch timeinsecond "command" Show Sample Output
The simplest way to do it. Works for me, at least. (Why are the variables being set?)
This command is adapted from http://otomaton.wordpress.com/2012/12/26/find-broken-symbolic-links/
Solutions with
find -L
don't work when the link is a loop, an error message is printed.
su www-apache/ftp user and then check readable: find ~/ -type d \( -wholename '/dev/*' -o -wholename '/sys/*' -o -wholename '/proc/*' \) -prune -o -exec test -r {} \; -exec echo {} readable \; 2>/dev/null check writable: find ~/ -type d \( -wholename '/dev/*' -o -wholename '/sys/*' -o -wholename '/proc/*' \) -prune -o -exec test -w {} \; -exec echo {} writable \; 2>/dev/null
Oddly, the isatty(3) glibc C call doesn't have a direct analogue as a command 'isatty(1)'. All is not lost as you can use test(1). For example, your script might be run from a tty or from a GUI menu item but it needs to get user-input or give feedback. Now your script can test STDIN with 'isatty 0' or STDOUT with 'isatty 1' and use xmessage(1) if the tty is not available. The other way to test for this is with 'tty -s' - but that's only for STDIN.
Revised approach to and3k's version, using pipes and read rather than command substitution. This does not require fiddling with IFS when paths have whitespace, and does not risk hitting command-line size limits. It's less verbose on the missing files, but it stops iterating at the first file that's missing, so it should be definitely faster. I expanded all the qlist options to be more self-describing.
You can use -e to pass multiple patterns.
Applies each file operator using the built-in test.
testt /home/askapache/.sq
/home/askapache/.sq
-a True - file exists.
-d True - file is a directory.
-e True - file exists.
-r True - file is readable by you.
-s True - file exists and is not empty.
-w True - the file is writable by you.
-x True - the file is executable by you.
-O True - the file is effectively owned by you.
-G True - the file is effectively owned by your group.
-N True - the file has been modified since it was last read.
Full Function:
testt ()
{
local dp;
until [ -z "${1:-}" ]; do
dp="$1";
[[ ! -a "$1" ]] && dp="$PWD/$dp";
command ls -w $((${COLUMNS:-80}-20)) -lA --color=tty -d "$dp";
[[ -d "$dp" ]] && find "$dp" -mount -depth -wholename "$dp" -printf '%.5m %10M %#15s %#9u %-9g %#5U %-5G %Am/%Ad/%AY %Cm/%Cd/%CY %Tm/%Td/%TY [%Y] %p\n' -a -quit 2> /dev/null;
for f in a b c d e f g h L k p r s S t u w x O G N;
do
test -$f "$dp" && help test | sed "/-$f F/!d" | sed -e 's#^[\t ]*-\([a-zA-Z]\{1\}\) F[A-Z]*[\t ]* True if#-\1 "'$dp'" #g';
done;
shift;
done
}
Show Sample Output
This method does not transfer the contents of the entire file, instead it computes a md5 sum of the file on each end so that large files can be compared without transferring them across the net.
`while true`: do forever `nc -l -p 4300 -c 'echo hello'`: this is the but anything can go here really `test $? -gt 0 && break`: this checks the return code for ctrl^c or the like and quite the loop, otherwise in order to kill the loop you'd have to get the parent process id and kill it. Show Sample Output
only simple example how to combine rclone & jq Show Sample Output
find broken symbolic links Show Sample Output
Got the idea from there http://fixunix.com/questions/15902-bash-checking-if-env-var-set.html Show Sample Output
allows command to use switches
The command creates new session "test", executes 'date' and then start your default shell (to keep the detached session alive). Change 'date' to fit your needs.
screen -r test
will attach the created session.
Given a hosts list, ssh one by one and echo its name only if 'processname' is not running. Show Sample Output
that's how I do it in ubuntu
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: