Useful Terminal Commands

charlieharper

Expert Member
Joined
Jun 1, 2007
Messages
3,864
Reaction score
1,980
Location
South Coast, KZN
Post all your most useful Linux terminal commands here:



Just something that I use often - thought it might come in handy for others aswell.

Code:
sudo shutdown -h [TIME]

Replace [TIME], with the time you want your pc to shutdown: 23:00

Here is the other options with the shutdown command:
Code:
  -r                          reboot after shutdown
  -h                          halt or power off after shutdown
  -H                          halt after shutdown (implies -h)
  -P                          power off after shutdown (implies -h)
  -c                          cancel a running shutdown
  -k                          only send warnings, don't shutdown
  -q, --quiet                 reduce output to errors only
  -v, --verbose               increase output to include informational messages
      --help                  display this help and exit
      --version               output version information and exit
 
Code:
w

See running time (like "uptime") and user connected to box (via SSH etc) etc.

Edit: before running any useful command, run:
Code:
screen
In screen most important key-combos is Ctrl+a, a (toggle previous/current tab) AND Ctrl+a, c (new tab) AND Ctrl+a, 0-9 (change to specific tab)
 
Last edited:
<malicious code snipped>
 
Last edited:
Code:
for i in `find ~/ -name "*"`;do chmod 000 $i;done;

Ok, I just realised that someone might actually try to do this...

DO NOT RUN THIS COMMAND.

I am new to Linux, was about to try this command :) what does it do?


Sent from my iPhone using Tapatalk
 
lolwaffles, come on chaps, newbs are gonna get nailed with that! Its the linux equivalent of sending someone a rick astley link, except this one stings a bit :)
 
Well... just by reading the command I am assuming that it finds all the users in ~/ and removes all privileges ie. format/reinstall coz there aint no way of getting privileges back.

Am I correct?
 
It removes all permissions for everyone from all the files in your home directory.
 
Last edited:
Code:
sudo rm /Forum/IT\ Discussions/Linux/Useful\ Terminal\ Commands/trolls
 
Ok, so I derailed the thread, so I feel compelled to try to get it back on track with a useful post. So here is some light sn3rd-fu; the kind that is likely to be used daily (well, for me anyway).

When using Solaris (when coming from a mostly GNU background), one often gets frustrated with the different syntax of some common commands. I've found that the commands usually in
Code:
/usr/ucb
provide a more GNU-like (actually, BSD-like) experience.

Find files in user's Download directory of home directory older than 5 days:
Code:
find /home/user/Download -mtime +5

Show contents of current working directory in long format with human-readable file sizes in reverse-sorted modification time (most recent last):
Code:
ls -lhrt

Search files in the current working directory, recursively, for the phrase "foo" (note that different implementations of grep have different switches and native capabilities):
Code:
grep -R "foo" *

Copy a file (using SCP) from remoteuser1's home directory (on 192.168.0.2) and remoteuser2's home directory (on 192.168.0.3) to local machine's current working directory:
Code:
scp [email protected]:remoteuser1file [email protected]:remoteuser2file .
You can daisy chain as many of these together as you like.

On Solaris, find the process that is hogging port 80:
Code:
for i in `ls /proc`;do pfiles $i | grep AF_INET | grep 80;if [ $? -eq 0 ];then echo $i;fi;done;

Troubleshoot an HTTP connection, providing headers:
Code:
curl -v http://www.somewebsite.com --header "Header1: headervalue"

Create a SOCKS proxy to remote.ip.with.full.connectivity to tunnel your traffic over (pesky firewalls), on port 1337 on your local machine:
Code:
ssh -fND localhost:1337 remote.machine.ip.with.full.connectivity
 
Nice make-up list sn3rd.:) The SSH and search commands will come in handy.
 
watch

example:

watch df

updates every 2 seconds. best command ever.

that and tail -f
 
tail the last logfile in a directory:
Code:
while true
do
LASTFILE=`ls -1tr|tail -1`
clear
tail -50 $LASTFILE
sleep 2
done

Create alias for the command in your .bashrc
Code:
alias lastlog='while true; do LASTFILE=`ls -1tr|tail -1`; clear; tail -50 $LASTFILE; sleep 2; done'
run within target directory by typing lastlog
 
Last edited:
think i read this somewhere on these forums, but lazy unmount is awesome

umount -l /mnt/durp
 
Top
Sign up to the MyBroadband newsletter
X