Introduction to Linux Commands. (New Linux Users Plz Read).

All threads related to any flava of Linux or BSD.
Locked
User avatar
WaZ
Sargeant at Arms
Posts: 173
Joined: Thu Oct 30, 2003 9:05 am
Location: /dev/null
Contact:

Introduction to Linux Commands. (New Linux Users Plz Read).

Post by WaZ » Wed Dec 17, 2003 11:17 am

Linux 201. An introduction to Commands. (by WaZ)

OK, assuming youve got your linux install going, you'll probably be faced with the task of mastering the Console.
Although many grphical tools now exist to manage most system configuration, those are only Front end for already existing programs/deamons.

§1. What is a Console/Terminal/Shell? And what Console/terminal/shell do you recommend?

A console is very to MS-DOS Prompt in Widows Operating System, with the big difference that you'll need to use it way ore for normal use then in windows.

There are two main types of terminal applications... Bash and Sh... and there are many types of X front ends for them. Ive always used bash and always will,
so the below tutorial is entirely Bash based. There are differences but for new users this shouldn't be a concern... So ill arbitrarely force u to learn Bash.

X front ends (aka XShells):

Tere are quite a few of them but the Most popular are:

Xterm.
Eterm.
Aterm.

Konsole (KDE based).
Shell (Gnome Based).

All of the above use exactly the same command, but have functionality and GUI differences.

My personal favourite is aterm. Because of its easy for transparency.

Eterm is also nice if you use Fluxbox for example for its Esetbg Pixmap Utility (basically to set wallpaper).

Konsole is nice because of its tab utility (great is u don't like many windows open and u want to for example monitor your firewall logs, your processes, etc... or to DoS (not that i would ever *grin*).

ok so basically use the one thats default to start learning it doesn't matter, you'll change terms after.


----------------------------------------------

CHANGE TO SUPER USER (root):
To gain root priviledges u can use the command:

su

You will then be asked to give the root password. Only root has access to the files situated outside the users home directory.

----------------------------------------------

HELP ON COMMANDS:
Most of the commands bellow can be used with arguments (usually a - with a letter).
To see a detailed summary (usually not very clear) of the arguments u can use on a certain command use:

--help --> Example: dir --help : will show all the arguments u can use in combination with dir.

----------------------------------------------


§2. Browsing directories / File Managing.

Ok here are the real basic command you need to know.
First a bit about the file system.

Youll need to know the basic directories.

/ -- the base directory. (the lowest u can go).
/bin -- file where the global binaries are executed. These are symbollic links to Executeable files. This means that any file in this represents a command in shell.
/etc -- Directory where configuration for global programs are set. (this really depends from how you install them)
/home -- Very important directory for everyday use... this is where user directories are set. This is where every user will have its personnal directory which he can manage etc...
/mnt -- mount directory, depending on the ditribution u use, this could be the directory where CDroms (or burners),DVDroms (or burners),external hd, etc.. will be mounted.
/root -- Super Users Home Directory.
/usr -- Directory where new programs will be installed. (Oversimplified)
/var -- Basically a directory where your Server (http/ftp/...) directories will be located.

ok the other directories are also important, but lets not overflow you with information yet.

Basic Commands:

A: cd
--go to directory.

cd blah: will make the shell go to the directory blah if there is such a subdirectory in the directory you are presently located.
cd /blah: go to the directory blah if there is such a directory in the base directory.
cd .. : (with the space) go to upper directory.
cd : (just cd) go to the users home drectory.

B: cp
--copy.

cp blah.txt /home/user/docs/blah.txt: Copy blah.txt in the current directory to folder /home/user/docs and name it blah.txt
cp blah.txt blah.txt.old: Copy blah.txt in the current directory by renaming it blah.txt.old (Note: this can be used to replace files)
cp /home/user/docs/blah.txt blah.txt: Copy the blah.txt in the directory /home/user/docs to the folder where i am and rename it blah.txt.
cp /home/user/docs/blah.txt /home/user/backup/blah.txt: Well u got the point ;-)

C: mv
--move.

mv /home/user/backup/blah.txt /home/user/docs/ move the file from the backup directory to the docs directory (basically cut/n/paste)
Note: u cannot rename the file while moving it. The second argument will always have to be a directory.

D: ln
--link

used to make for example symbolic links:

ln -s blah /home/user/ : makes a symbolic link of executable blah situated in current directory in user's home driectory.

E: rm
--remove

rm blah.txt: delete blah.txt
rm -R /home/user/blah : remove directory blah Recursevily (eg with all its subfolder.)
Note: rm only unlinks the file these can still be recovered.

F: shred
--Overwrite the specified FILE(s) repeatedly, in order to make it harder for even very expensive hardware probing to recover the data.

shred blah.txt: delete blah.txt and make sure noone will be able to recover it.

G: rmdir
--remove the Directory(ies) it and only if they are empty.

this is to remove empty directories...

H: mkdir
--make directory

pretty self explanatory.

I: dir
--show content of current firectory

there are many options u can additioaly use... but...

dir | more : will display till current shel window is full (then use enter to go to next line / space to refill whole screen)

Note: the | more argument can be used for every command/program etc... this can be usefull if u want to monitor everything.

J: ls
-list

basically the same as dir but will use colors to help you identify of what type the entries are. (90% of the time i use ls instead of dir.)


§3. Permission Commands:
Those are used to allow/dissalow access to certain users.

A: chmod
--give permission of file to

this will give the file(s)/directory(s) access to specified users.

chmod a+x blah: a stands for all. x means execute. this would give all the permission to execute.

there are also numeric arguments instead of the a+x for example... 777 will for example give permission to all.

B: chown
--give ownership to

chown user blah: give ownership of file blah to 'user'.
chown user:group blah : give ownsership to 'user' in group named 'group' of file blah. (this is used if there are multiple groups having 'user')

C: chgrp
--give ownership of file to this group

pretty self explanatory.

Note: the -R argument can be used in all 3 commands in order to make the command recursive (e.g. apply to all subdirectories also)



§4. Miscelaneous Commands:

These are application (and app related) commands that are often used.

./blah : launch executable blah situated in current directory (executables usually have no extension or a .bin / .sh extension).
Note: .bin /.sh are usually installation binaries as oposed to unextended executables who are just the launch file.
Note2: if u make a symbolic link (ln -s) of the executable (launch file) in directories /bin (note recommended); /sbin (not recommended); /usr/bin ; /usr/share/bin or /usr/local/bin u will be able to launch the program from any position in the filesystem.
Warning: DO NOT OVERWRITE ANY PRESENT SYMBOLIC LINKS IF YOU DON'T WANT TO MESS UP YOUR SYSTEM.
Note3: bin is the linux Kernel Binary folder, sbin is the system binary folder (eg your distributions default symbollic links.)

startx : starts the X server (the Linux GUI)

gdm / kdm : start the Gnome / KDE Desktop Manager

ping : ping target (try ping google.com then press ctrl-c to stop process)

ps axu: list all processes (use ps axu | more if too many)
ps u: list all processes initiated by current user.
ps -U user: list all processes initiated by 'user' (this can be used to see root processes for example)

using ps axu u can see the process ID (the process number) using that u can:

kill : use it like this: kill 12457 -will kill process number 12457.

killall : use it like this: killall xmms -will kill all processes related to xmms.

reboot : reboots your computer.

shutdown : shuts down your computer.

ifconfig: shows configuration of network interfaces (use: ifconfig -a for all ; ifconfig <int> for specified interface).

lsmod : shows loaded kernel modules (drivers)

vi : view a file in shell. (use vi blah.txt)

vim : vi modified more elaborated version of vi (still in shell tho)

gvim : Graphical version of vim (Notepad with syntax highlighting basically)

mount : mount a device
example: Mounting a cdrom drive: mount /dev/cdrom /mnt/cdrom will lets you browse your cdrom from directory /mnt/cdrom
example 2: Mounting a Win 9x Partition: mount -t fat32 /dev/hda1 /mnt/WinC (of course the target folder changes from ditribution to distribution)
Note: u can change the default folder for your devices in config fles /etc/fstab and /etc/mtab (DONT PLAY WITH IT IF U DONT KNOW HOW IT WORKS THO)

umount : unmount a device. (Note not unmount, umount)

wmget : Downloads a file from internet (FULL PATH)

info: a rather long and unclear command list with brief description.

top: real-time processes monitor with cpu load and all.

uptime : how long your system has been on.

hostname : prints the hostname of your system

w : shows what users are logged in and what they are doing (nice for security monitoring)

pwd : print working directory (print full path of your current position)

history : shows the last 1000 commands used (history | more is recommended )

tar : untar a compressed archive. (use tar -xf extracts files from a .tar archice... use -tvf for testing , shows the files in archive)

df : disk free: prints your disk information ( use -h argument for 'human readable form')

traceroute : trace an IP. (use traceroute ip/domain)

nmap : scan an ip for open ports. (use nmap ip)


§5. Packaging system Commands and Compiling.

Compiling:

To compile, the usual method is to first configure a makefile, to do this use:

./configure (sometimes ./config )

Then u compile the program:

make

Finally u install the program (It is usually done as a super user so all users can use the program if however u install with your usual username it will make a local installation in your home directory))

make install.

-Debian:

for .deb files:

dpkg -i blah.deb (as root): to istall
dpkg --purge blah.deb : to uninstall

using apt:

apt-get install blah : installs application blah if found on server
apt-get remove blah : removes application blah.
apt-cache search blah : searches for blah in your apt archive
apt-get update : updates your archive (you should do this at first boot before attempting to install, also do it frequently to take changes into consideration)
apt-get upgrade blah : upgrades program blah.
apt-get dist-upgrade : upgrades your whole system.


-RPM (for SUSE / Redhat / Fedora / Mandrake / ...)

rpm -ivh blah.rpm : install binary blah.rpm (with information)
rpm -Uvh blah.rpm : update blah using blah.rpm
rpm -e blah : uninstall (remove) blah
man rpm : read the rpm manual.

Note: there are other tools like urpmi / up2date / and apt-get-rpm which i never used and therefore wont comment.


-Gentoo (Copy pasted from: http://www.ms.mff.cuni.cz/~mtrc8674/min ... entoo.html )

emerge [r]sync : update portage tree
emerge -npv [package|ebuild|system|world] : -n skip already installed packages (noreplace), -p pretend installation (show package collisions), -v show enabled/disabled USE flags
emerge search [-S] name : search for package name in portage tree; name could be "^kde" or "gcc$"; -S search as well in package description
emerge unmerge name : remove all matching packages
etc-update : a tool that handles configuration file updates


§6. Final Note.

It is my belief that using linux without using shells is not really using link, since only in shell will you be able to fully control and monitor your systems activity. Please take the time to dig into the commands, play with them, etc... This will in the end make your linux experience a lot more gratifying.

OK, i think im about done here... Hope i could help.


-WaZ-

PS: This mini tutorial is purposefully Simplified to try and not overflow the ones reading it with information.
Last edited by WaZ on Wed Dec 17, 2003 12:04 pm, edited 3 times in total.
"To be a nemesis, you have to actively try to destroy something, don't you? Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect." -Linus Torvalds

Locked