PDA

View Full Version : Helpful Linux/Unix Commands


mikeyp
04-02-2006, 06:44 AM
(posted by mikeyp)
I got really bored and decided to write a small "help file" on some useful unix commands. The intended audience is those who are new to linux/unix and have no idea what to do in a shell. This is by no means a full list of every command you would need, but just a small drop in the pond. Feel free to add some if you'd like. If this is useful to others I will add some more later.

Notes:
file- some file that you wish to run a command on.
x- an integer.
command- some unix command.
path- a path to a file or directory, ex: /home/user123/ or /var/logs/log123.log
Most if not all options can be used together.


head <file>:
head prints the first few lines (10 by default) of a file. Very useful if you want to look at a few lines of a file without going into an editor. To print more/less lines use the -n option. The command would then be "head -n x file".


tail <file>:
tail prints the last few lines (10 by default) of a file. Very useful if you want to look at a few lines of a file without going into an editor. To print more/less lines use
the -n option. The command would then be "tail -n x file". tail also has a very useful option called "follow". If the file is edited it will print out the lines again. This is handy if you are looking at log files. The command would be "tail -f file". To use both the -n and -f options the command would be "tail -fn x file".


man <command>:
man is the unix manual command. If there is a manual entry for the command entered it will display all the options available and what they do. Extremely useful.


ls <path>:
ls shows the contents of the specified directory. If you just use "ls" it will display the contents of the current directory. The -a option shows all files, even hidden ones (hidden files have a '.' prefix in linuz/unix). The command would then be "ls -a". The -l option shows a long listing of each file in the directory (current or otherwise). It will show the files permissions, timestamp, owner, group and size among other things.


cd <path>:
cd is the change directory command. The path must be to a directory, not a file. If just "cd" is used it will take you to your home directory. To go one directory down use "cd ..".


mv <file> <path>:
mv is the move command. It will move the file/folder to the specified path.

cp <file> <path>:
cp is the copy command. It will copy the file/folder to the specified path. The original still exists.

(posted by Vege)
df -h //shows disk usage in human readable format
updatedb // followed by
locate X // find X string from your computer


(posted by nox-hand)
Chmod:
chmod <number code> <file name>
This command will change the permissions of the designated file. If you, for example, wanted to let EVERYBODY (I mean anyone here, not just your family or friends, but even someone else, like me !!), you'd use:


chmod 777 file.name

There are different number codes for what you need to do. I suggest you typing the following command to learn more about chmod:

Code:

man chmod


(posted by jatos)
ps -A
list all active processes

kill
kills a process with a given PID

init 123456
Change computers init level

shutdown
self explanatory really

chown
Change file ownership

(posted by Crouse)
Over 500 Linux commands:
http://www.linuxdevcenter.com/linux/cmd/

Tons of info on bash scripting : http://bashscripts.org

nox-Hand
04-03-2006, 08:03 AM
Nice thread, mikeyp! :)

Very good for all the newbies :D

I think you should put it like:
cp <file> <path>
instead of:
cp file path

I think that would help a lot :)

I wonder how long this list'll get?

nox-hand

mikeyp
04-03-2006, 11:41 AM
I think you should put it like:
cp <file> <path>
instead of:
cp file path


Good idea.

nox-Hand
04-03-2006, 11:43 AM
Great job! I think I might concoct some additions some time if I may? :) But as I have a partial PC ban right now, I cannot. I will wait untill later with that ;)

nox-Hand

mikeyp
04-03-2006, 11:50 AM
Great job! I think I might concoct some additions some time if I may? :) But as I have a partial PC ban right now, I cannot. I will wait untill later with that ;)

nox-Hand

Of course, add all you want.

nox-Hand
04-03-2006, 12:21 PM
Great! I will keep this thread in mind :)

nox-Hand

nox-Hand
04-05-2006, 04:47 PM
My little addition (I aint got much time, feel free to add these to first post, so we might get a sticky if we set it up right :P)

Chmod:
chmod <number code> <file name>
This command will change the permissions of the designated file. If you, for example, wanted to let EVERYBODY (I mean anyone here, not just your family or friends, but even someone else, like me :shady:!!), you'd use:
chmod 777 file.name
There are different number codes for what you need to do. I suggest you typing the following command to learn more about chmod:
man chmod


Sorry, I aint got time for more :(

Will write more later!

nox-Hand

Tham
04-12-2006, 02:31 PM
perhaps run through how to write bash scripts? Something simple like changing multiple directories.

nox-Hand
04-12-2006, 02:49 PM
Sounds like an idea, but not something I have time for right now..


nox-Hand

Tham
04-20-2006, 12:37 PM
You could always try the old:
rm * -r
I hear that solves all your problems lol.
(newbs beware....just dont...)

nox-Hand
04-20-2006, 12:40 PM
Nono, that's rm -r /, that works much better..

DO NOT, I repeat, DO NOT use this command unless you want your HDD's wiped completely..

I did this once... =(


nox-Hand

Doug.Mellon
04-24-2006, 09:53 PM
You could always try the old:
rm * -r
I hear that solves all your problems lol.
(newbs beware....just dont...)

hahahahaha... that was a good one after just reading the other thread about that not to long ago.
haha. Take care,
Doug

nox-Hand
04-25-2006, 09:03 AM
Meh... Just coming in here to make fun of me... :burnt:

nox-Hand

jatos
04-25-2006, 10:01 AM
ps -A
list all active processes

kil
kills a process with a given PID

init 123456
Change computers init level

shutdown
self explanatory really

chown
Change file ownership

nox-Hand
04-26-2006, 05:02 PM
killall <appname>

Will kill your app COMPLETELY

I use it to kill runaway mplayer's :P

nox-Hand

Vege
04-26-2006, 05:35 PM
df -h //shows disk usage in human readable format
updatedb // followed by
locate X // find X string from your computer

mikeyp
04-28-2006, 03:12 AM
perhaps run through how to write bash scripts? Something simple like changing multiple directories.


It would be hard to write a whole tutorial on how to write bash scripts. I could throw one together that changes multiple directories for you though if you want.

mikeyp
04-28-2006, 03:14 AM
Good job all! The shell prompt can be intimidating for someone who is new, so having our commands here might help them a little bit.

nox-Hand
04-28-2006, 12:43 PM
Now all we need, is the first post edited with all the commands in, maybe an index some time, and we may get sticky :P

nox-Hand

Crouse
05-13-2006, 03:36 AM
Over 500 Linux commands:
http://www.linuxdevcenter.com/linux/cmd/

Tons of info on bash scripting : http://bashscripts.org

nox-Hand
05-13-2006, 09:10 AM
Noes! We should have our own guide ;)


nox-Hand

Tham
05-16-2006, 01:39 PM
lol yeah. Anyone can go through a book and see endless amounts of commands...but to them its all jargon deet de dee. What makes this thread special is that its going to list...describe...opinionate usefullness...and demonstrate what each command does. A little warmer than just listing command after command.

nox-Hand
05-16-2006, 01:46 PM
Hear hear! :agree:

So, what should we add?



nox-Hand

mikeyp
06-12-2006, 09:09 PM
After being gone for a few months I finally updated the first post. :)

nox-Hand
06-13-2006, 03:36 AM
Great job, mikeyp! Not we have two nice Linux guides in the Linux section :D

nox-Hand