

Command line tricks - r11t
http://www.tuxradar.com/content/command-line-tricks-smart-geeks

======
Periodic
Regarding the SSH tricks:

If you change the port of SSH, change it to still use a port under 1024. On
most Unix systems these are privileged ports that require root to open. This
ensures that if there is a process listening there that it was opened by root
and not some intruder hoping to get your password to sudo to higher
privileges.

Regarding removing reserved space:

Be careful doing this on some file systems. Some filesystems may need to write
more data to a journal or are set up with copy-on write and will not be able
to delete files if you have no space left on the disk. Reserving a little
extra space for this can be necessary. A little extra space also lets you have
some space to work with if you need to temporarily create or move files before
you can free up the space.

Also, if you're going to use a non-standard port, set up your .ssh/config!

    
    
        Host s
            hostname server
            port 666
    

That is a little more versatile than setting up an alias as it will work from
any shell and you can specify any ssh daemon in there.

See `man ssh_config` for more info.

~~~
JoachimSchipper
Additionally, (almost all) Unix filesystems do not fragment under normal use.
This is far superior to FAT, which does have this problem, but also means that
there's typically no way to defragment them short of recreating them.

A nearly-full disk is _not_ "normal use" in the above sense.

~~~
ciupicri
XFS (from SGI) has xfs_fsr for defragmentation. It's not perfect, but it's
better than nothing.

------
mike463
I loved these tricks. Here's a site dedicated to command line tricks:

<http://www.commandlinefu.com/commands/browse/sort-by-votes>

Being on a Mac, I didn't have the rename or prename command, but after a lot
of searching, found it here:

<http://www.perlmonks.org/?node_id=303814>

(beware the '+' signs at the beginning of each line)

------
onewland
It's a pet peeve of mine to see

    
    
      cat [one-file] | less
    

`less` takes a file as an argument.

    
    
      less [one-file]
    

only requires you to run one program, and I/O tends to be really slow.

~~~
prodigal_erik
You're not the only one, this inspired the Useless Use of Cat Award (a few
other strange practices are covered here as well):

<http://partmaps.org/era/unix/award.html>

------
tudorachim
tar -xvf infers the filetype from the file; obviating the need for the smart
untarring script.

edit: Also, another useful thing is <command> | xargs -n1 -I{} <stuff>, which
runs stuff once on every element of the output of command, replacing every
occurrence of {} with the element. Then you can do something like "ls *.mp4 |
xargs -n1 -I{} mv {} `basename {}`.mp3" .

~~~
tyrmored
I quite like using for loops for that. I use it a lot for batch audio
conversion with ffmpeg:

for f in *.wma; do ffmpeg -i "$f" "${f/.wma/.mp3}"; done

~~~
Periodic
I end up using this template for a lot of operations. Where rename really
seems applicable is when you want to do complicated renamings such that
regular expressions really are appropriate.

~~~
tyrmored
Yeah. I used to love Bash but these days anything that takes more than a
couple of lines I just use Perl. Its ubiquity helps a lot.

------
mcantor
You can also expose a file in a one-shot webserver using netcat:

    
    
        cat somefile | nc -q1 -l -p8081

~~~
ciupicri
I prefer:

    
    
         nc -q1 -l -p8081 < somefile

------
JoachimSchipper
The given syntax for prename is very odd, and e.g.
<http://man.he.net/man1/prename> has a much more sensible explanation of what
the command does (i.e. _remove_ _bak).

The script under "crash test dummy" is hackish and full of race conditions,
but that's perhaps acceptable in that case.

Leaving webmin and X open to all local users (in the case of webmin, by
choosing a bad password) is not a good idea.

------
tyrmored
I love this sort of stuff. The first few "top ten" command line tricks
articles I found back when I was enthralled with the power of the Bash shell
have probably saved entire days of my life by now.

------
Jach
I really liked this list, especially all the remote stuff. Though he did make
an error: lower nice values get "more favorable scheduling". That's why +10 is
default.

------
ciupicri
Regarding "Editor redirection": why should we complicate ourselves with
/etc/alternatives when the EDITOR and VISUAL environment variables can be
used?

------
ciupicri
The root account from RHEL and Fedora systems is configured by default with
safe-delete command aliases.

