Handy Linux User Commands

../ represents one directory higher
cat filename display file contents
cat stuff1 stuff2 > allStuff combine files
cat someStuff >> allStuff append to a file
cd dirName go into the directory dirName
chmod [permission mode] file change the permission of a file (4=read, 2=write, 1=execute for user/group/all)
chown user file change the owner of a file
clear clear the terminal
cp file1 file2 copy file1 to file2
date print current date and time
find someStuff locate a file or directory
finger user get some info about a user
free display some stats about memory usage
ftp hostname connect to an ftp server
gunzip file.gz extract contents of gzipped compressed files
hostname display the hostname of the computer
kill [ID] terminate a process
less file view file in terminal with ability to scroll up and down
ln sourceName destDirectory create symbolic link to a file
locate file locate a file from a database maintained by the computer
login login to the computer
lpr file sends a file to the print spooler
ls list the contents of the current directory
ls directory list the contents of a given directory
man program display manual pages for a program
mkdir directory create a directory
more file view file in terminal with ability to scroll down
mv source target move a file
passwd user change a user's password
pico file open a file in the pico text editor
pwd print the full pathname of the current directory
quota user display the disk quota allocated to a user
rm file delete a file
rmdir directory delete a directory
rm -rf anything forcefully delete something (like a directory, recursively)
sh the standard Unix shell, bash
ssh hostname open an ssh session
su switch to the superuser's (root's) identity
su user switch to another user's identity
tail file print the last 10 lines of a file
telnet hostname open a telnet session
touch file update the access time and last modified time for a file to the current time and date
uname -a print system information
vi file open a file in the vi or vim text editor
who am i gives info about the current user
who -uH gives info and idle times for all users

Handy Linux Sys Admin Commands

halt shuts down the machine
mount /mnt/floppy mounts the floppy fs
mount /mnt/cdrom mounts the cd-rom fs
shutdown -r "now" restarts the machine
umount mountedLocation unmounts a filesystem
update db update file database used by locate command

Recommended Answers

All 18 Replies

A few minor corrections:
ln sourceName destDirectory create symbolic link to a file
Should be:

ln -s source destination (the -s switch denotes a symbolic link)
sh the standard Unix shell, bash
Should be:

sh is the standard UNIX shell.
bash is the Bourne Again SHell, standard on most Linux systems. UNIX doesn't come with bash, unless it's installed seperately.


Handy Linux Sys Admin Commands
mount /mnt/floppy mounts the floppy fs
Should be:

mount /mnt/floppy mounts the floppy device (if /mnt/floppy is the mountpoint)
mount /mnt/cdrom mounts the cd-rom fs
Should be:

mount /mnt/cdrom mounts the CD-ROM device (if /mnt/cdrom is the mountpoint)
shutdown -r "now" restarts the machine
Should be:

shutdown -r now (no quotes)
or even reboot on some systems

update db update file database used by locate command
Can also be:
updatedb or /usr/libexec/locate.updatedb

Hey there. Thanks so much for the corrections. Perhaps you can expand on my list?

Sorry I've been away for awhile - work followed by a sunny vacation in Florida, doncha know...

I'll be posting a bunch of stuff next week after I get caught up at the office. Some howto's, cheat sheets, walkthroughs, etc.

If anyone has any requests, drop me a line, and I'll see what I can crank out for you.

wc -l <file> counts the number of lines in a file
wc -w <file> counts the numbers of words in a file
wc -c <file> counts the number of bytes in a file
wc -m <file> counts the number of characters in file

You can combine with other commands ie:

ls | wc -l will count the number of files in the current directory.
cat /etc/passwd | wc -l will count the number of entries in /etc/passwd

Member Avatar for TKSS

sometimes you have to specify how to mount a device as well...for instance...I have a second hard disk that is /dev/hdc

In order for me to use it, I have to mount it. In which case I would do the following:

>mount -t reiserfs /dev/hdc /mnt/share.drive (or whatever you want to mount it to in your File sys)

I use reiserfs for my storage drives since I store mostly mp3s, videos, and pics...so sub whatever you'd use in for it.

Also, you'd make changes to your /etc/fstab to automount that same mount you just did the next time you rebooted. :)

another useful command that can be found is 'netstat' this can be used the same as on windows except with redhat, there are certain flags you can use.

ie.
netstat -a = shows all network traffic
netstat -an =shows all network traffic using numerical ips
netstat -anp = shows all network traffic using numerical ips and what programs they are associated with.

grep put in stout the line that has the spec word

ps check for all processes that are running

grep + ps in action

#ps aux| grep root

the stdout will be all line that got the wrd root instead

less helpfully command to format the output of a command, like the one above, this stout will be scrollable up/down

more like "less" but scrollable only down

ex.

ls /etc | less

[: sorry for my english :]

Another handy one is sort

For example a script that shows disk usage per directory sorted largest first:

du $1 > /tmp/du.out
sort -k1nr -odu.sort.out /tmp/du.out
rm /tmp/du.out

-k1nr tells sort to order the file on the first column, numerically, in reverse order

Tried to get it to work without the temp file but couldn't. For some reason sort refused to accept the output from du through a pipe (but maybe I did something wrong).

Thanks! I am new to RED HAT, and have found this very helpful.
I came to this site for C++ help and yet here I also find help to configure samba,

and help on linux command! I LOVE this site! keep up the good work.

I like this one : ls -l|sort +4nr|more - sorts the largest dir in your mail log

Hello every one. I'm very new in Linux. I have worked on AIX and for what I have seen, the commands and structure are very much close.
The question is:
When I logon to Linux box, I have Korn Shell as the default shell. I know you can switch to other shells (born etc).
So in my pervious environment (aix) my .profile I have the following statements:
~~~~~
VISUAL=vi

#Setup for FULIST

FUPATH=/usr/local
export FUPATH

#Setup for VE

VEPATH=/usr/local
export VEPATH
VVTERM=aixterm

#Below is magic code to enable command line editing. Up/down arrows retrieve previous commands. Left/right move in command line, backupspace to delete.
#
set -o emacs
set -o ignoreeof
alias __A='^P'
alias __B='^N'
alias __C='^F'
alias __D='^B'

what can I do for linux to get this kind of setup

Does any one know the command that shows you the filsystem information. For instance, if I want to know how many disks are in a particular filesystem.
In AIX , you have something like this "lslv -l <lv_name>.
So what's the equivalent command for LINUX SUSUE.

Thank you.

cat /etc/fstab

will show the list of partitions/slices that are mountable on the system, along with their filesystem.

Example (from a FreeBSD system):

cat /etc/fstab

# Device                Mountpoint      FStype  Options         Dump    Pass#
/dev/ad0s1b             none            swap    sw              0       0
/dev/ad0s1a             /               ufs     rw              1       1
/dev/ad0s1f             /tmp            ufs     rw              2       2
/dev/ad0s1g             /usr            ufs     rw              2       2
/dev/ad0s1e             /var            ufs     rw              2       2
/dev/acd0c              /cdrom          cd9660  ro,noauto       0       0
proc                    /proc           procfs  rw              0       0

The same command works on Linux, Solaris, HP-UX (I think) and the BSDs. If you need to check NFS stuff, it varies by OS.

ps ax | grep init
If using grep commend like above it won't repeat once same.

ps ax | grep init | grep -v grep
If using grep commend like above it won't repeat once.

Chandhru :idea:

VISUAL=vi
FUPATH=/usr/local
export FUPATH

#Setup for VE

VEPATH=/usr/local
export VEPATH
VVTERM=aixterm

#Below is magic code to enable command line editing. Up/down arrows retrieve previous commands. Left/right move in command line, backupspace to delete.
#
set -o emacs
set -o ignoreeof
alias __A='^P'
alias __B='^N'
alias __C='^F'
alias __D='^B'

This should work in linux, since korn is what does the work in this instance basically if ksh can interprete this in AIX it should work in linux, unless you are using pdksh (public domain korn shell) which isn't entirely compatible with ksh93 (but should be 100% compatible with ksh88).

I also use korn as my default shell it is a lot more powerful that bash and all the bash derivatives (tcsh, zsh)

tcsh is a C shell variant...

2 things you don't want to type:

  • rm -Rf /*
  • dd if=/dev/zero of=/dev/(your HD here)

hi everyone. even i am new to linux. in fact i was looking for something like that just to get started with linux. i guess i found what i wsa loking for keepmit up and eway to go

How do I make it all user can shutdown using unix/red hat 7.2? It is not hook up to the internet. I am using for school.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.