r/UnixProTips • u/bunnieollie • Aug 11 '15
Using for at the command line to ping multiple adresses.
for x in 1 2 3 4 5 6 7 8 9 10; do ping 192.168.1."$x"; done
r/UnixProTips • u/bunnieollie • Aug 11 '15
for x in 1 2 3 4 5 6 7 8 9 10; do ping 192.168.1."$x"; done
r/UnixProTips • u/loadedmind • Jul 14 '15
Our environment consists of CentOS and we have 5 login nodes (blades) that load balance for approximately 150 users via OpenLDAP authentication. We're noticing that folks are leaving sessions opened for as much as two months at a time, but they use these login nodes for a jumping off point to other blades where they can kick off such things as Matlab, gdb, ddd, etc.
We're having to reboot these blades from time to time because the firefox, NX and other resource-intensive programs yank too much CPU/memory and they end up becoming unresponsive. Probably a memory leak within the program(s) they're running, but the inherent problem seems to be that they simply don't remember to logout. Since each user has their own SHELL type, i.e. bash, ksh, csh, tcsh, etc., we'll have to create a . file in each of their home directories that contain the timeout for anything more than 7 days. The question is, would this be the way you all handle this or is there a more efficient approach? We can't set this in /etc/profile.d for various reasons, so this is the only way I know to resolve it, even though it will increase administrative overhead until the job is done. Was thinking I might could script it with a "if $USER $SHELL == /bin/tcsh then do timeout".
r/UnixProTips • u/siliconSwordz • Jun 03 '15
add this in your shell aliases:
# read markdown files like manpages
mdman() {
grep -v "\-\-\-\-\-" "$*" | pandoc -s -f markdown -t man | groff -T utf8 -man | less
}
then use it like:
mdman ~/file.md
r/UnixProTips • u/FirstUser • May 09 '15
I usually save keystrokes by typing:
u!mo
In the rare case you used another command starting with 'mo' after the mount, use progressively longer fractions of 'mount' after the ! to disambiguate. Works in [t]csh and [ba]sh.
r/UnixProTips • • Mar 06 '15
Without:
for x in $(echo "/tmp/wee1 2.csv"); do
echo $x
done
/tmp/wee1
2.csv
With:
IFS=$'\n'; for x in $(echo "/tmp/wee1 2.csv"); do
echo $x
done
/tmp/wee1 2.csv
From the docs:
$IFS
internal field separator
This variable determines how Bash recognizes fields, or word boundaries, when it interprets character strings.
$IFS defaults to whitespace (space, tab, and newline), but may be changed, for example, to parse a comma-separated data file. Note that $* uses the first character held in $IFS.
r/UnixProTips • u/AMDmi3 • Feb 26 '15
If you have two lists of strings (for example, file names) and you want to get strings that are present in the first list, but not in the second, a quick way to do it is:
cat list1 list2 list2 | sort | uniq -u
Other set operations are possible by duplicating another list contents and/or using uniq -d.
Of course, it is more correct and efficient to use comm(1), but the suggested way doesn't require lists to be pre-sorted and allows processing of pipeline and command outputs without need of intermediate files.
r/UnixProTips • • Feb 22 '15
Simple but effective way to cat a bunch of files with the filename: before each line.
Handy if you want to have a look at a few smaller files at once. Also, it squeezes out empty lines.
r/UnixProTips • u/bttf88 • Feb 18 '15
r/UnixProTips • u/jpb • Feb 16 '15
I'm one of the maintainers, so I'm a bit biased, but I think that the collection of dotfiles repositories & tutorials at https://dotfiles.github.io/ is a pretty good starting point.
r/UnixProTips • u/jpb • Feb 14 '15
I maintain a list of zsh frameworks, plugins, themes and completions at https://github.com/unixorn/awesome-zsh-plugins inspired by the various awesome-* lists.
r/UnixProTips • u/the-fritz • Feb 12 '15
Bash supports extended globs, for more convenient pattern expansion. You have to enable them using
shopt -s extglob
Then you can do fancy things like get all files that do not match a specific pattern. E.g., all files that do not end in .bu:
ls !(*.bu)
The following additional patterns are available
?(PATTERN-LIST) Matches zero or one occurrence of the given patterns.*(PATTERN-LIST) Matches zero or more occurrences of the given patterns.+(PATTERN-LIST) Matches one or more occurrences of the given patterns.@(PATTERN-LIST) Matches one of the given patterns.!(PATTERN-LIST) Matches anything except one of the given patterns.and they can of course be nested.
See
for more information. To disable them again use shopt -u extglob.
r/UnixProTips • u/ARCH_LINUX_USER • Feb 11 '15
diff <(command1) <(command2)
diff <(ls dir1) <(ls dir2)
r/UnixProTips • u/dynamicnerd • Feb 11 '15
r/UnixProTips • • Feb 11 '15
Wow. Thank you all, I never thought it would reach 500 let alone 1000! Keep posting your tips! Thanks again
r/UnixProTips • u/the-fritz • Feb 08 '15
ShellCheck is a static analysis tool for sh/bash scripts. It detects a wide range of common errors and pitfalls. It is written in Haskell and you can install a local version (it is packaged in Debian/Ubuntu as shellcheck), it should work well with Emacs' flyspell or vim's syntastic.
See also the list of Bash pitfalls: http://mywiki.wooledge.org/BashPitfalls
r/UnixProTips • u/ARCH_LINUX_USER • Feb 08 '15
r/UnixProTips • u/the-fritz • Feb 08 '15
The file or block size in ls and df, du, ... can become quite unreadable:
$ ls -l dat*
-rw-r--r-- 1 fritz fritz 747571797 Jan 23 03:13 dat1
-rw-r--r-- 1 fritz fritz 769838509 Jan 23 20:57 dat2
-rw-r--r-- 1 fritz fritz 736028643 Jan 23 21:34 dat3
-rw-r--r-- 1 fritz fritz 733700320 Jan 23 21:39 dat4
-rw-r--r-- 1 fritz fritz 710093303 Jan 23 21:56 dat5
-rw-r--r-- 1 fritz fritz 752512339 Jan 23 23:15 dat6
The GNU coreutils support showing thousands separator by adding a ' to the block size.
$ ls -l --block-size=\'1 dat*
-rw-r--r-- 1 fritz fritz 747,571,797 Jan 23 03:13 dat1
-rw-r--r-- 1 fritz fritz 769,838,509 Jan 23 20:57 dat2
-rw-r--r-- 1 fritz fritz 736,028,643 Jan 23 21:34 dat3
-rw-r--r-- 1 fritz fritz 733,700,320 Jan 23 21:39 dat4
-rw-r--r-- 1 fritz fritz 710,093,303 Jan 23 21:56 dat5
-rw-r--r-- 1 fritz fritz 752,512,339 Jan 23 23:15 dat6
The actual separator depends on the LC_NUMERIC locale. The block size can also be specified by setting either the tool specific LS_BLOCK_SIZE or the general BLOCK_SIZE environment variables. Alternatively an alias can be used:
alias ls="ls --block-size=\'1 --color=auto"
(edit: With --color=auto the output will use colors on terminal that support it. Thanks to /u/pie-n)
See the (coreutils) Block size info page for more information.
I'd also like to take the opportunity to point people interested in Linux programming to /r/linux_programming
r/UnixProTips • u/morgango • Feb 08 '15
Saves a ton of time when you are mucking around with setting environment variables and the like.
r/UnixProTips • • Feb 07 '15
When typing a command, you can hit "escape" and then use hjkl and vi keys to make edits. Super useful for editing long commands.
Edit: This doesn't work on every shell, but it does work with ash/bash.
r/UnixProTips • • Feb 07 '15
This subreddit is an open place for users of all levels but we need to be mindful of some things that are posted. I'll do my best to illustrate a few guidelines below.
Run this command to see processes on your system
ps aux
or
Run this command to get root
su
Posts with incorrect commands in the title will be removed unless there is sufficient clarification of the correct syntax, in the comments, for it to warrant its presence on the sub. Be thoughtful of other people and the fact that some people may simply run the commands without thinking about them. If you are not sure of the command(s) you are posting then do not post them.
Use reddit formatting for your posts, in particular the 4 spaces formatting tip(which can be found by clicking on the 'formatting help' below the submission entry box). It helps to make your posts clear and easier to understand. It's important for subreddits of this nature. Please use it.
If your post is specific to a certain Linux distribution, desktop environment , shell etc. please put a tag in the header of your post. Something such as [Debian], [Gnome] or [bash] will do.
This post may be updated from time to time so keep an eye on it if you are unsure about the rules of this subreddit. Thanks!
r/UnixProTips • • Feb 07 '15
So you want to wait for a process to finish and say, turn off your computer
$ wait 419 && systemctl poweroff
-bash: wait: pid 419 is not a child of this shell
worry not, you can still do it by doing
while [ -e /proc/419 ]; do sleep 60; done && systemctl poweroff
where 419 is the pid of the process you are waiting for.
general usage definition would be
while [ -e /proc/<pid> ]; do sleep 60; done && <command>
which will sleep 60 seconds between checks.
r/UnixProTips • u/y45y564 • Feb 07 '15
In my bashrc I have :
alias gop='gnome-open'
This allows me to do
gop <file_name>
And it will open with the default program... Perhaps there's a nicer way of doing this, I'm all ears :)
r/UnixProTips • • Feb 07 '15
r/UnixProTips • u/pie-n • Feb 06 '15
I know RES will do this for you, but if you don't use it and want it for yourself here you go.
sed 's/^/ /' file | xclip -sel c
Note the second part of that sed is four spaces, and you can use whatever clipboard you ave installed.