Webmaster Key - Discussion Forums


Welcome, Guest. Please login or register.
Did you miss your activation email?
February 09, 2012, 02:03:19 PM

Login with username, password and session length
Welceome to Forums!

Important information for guests and new members:

In order to understand the full benefits of becoming an active member of this forum, please review the following information on guest and new member restrictions. These forum changes have been prompted by an overwhelming and unreasonable amount of bot postings and incoherent guest spam messages. We wish to prevent these events from happening in the future and make our community a more comfortable place for all of our members.

For guests:

Guests are not allowed to open new topics, polls, or posts attachments.
If you wish to open up new discussions on this forum, we encourage you to register.

For new members:

New members with less than five posts are not allowed to modify additional profile information such as avatars, contact information, biographies, and signatures. However, new members are encouraged to post their own topics or reply to topics initiated by other members. Become active on the forums and 5 posts should be an easy task!

We are a diverse community with members from all over the world. We encourage new ideas and interesting conversation. Do not be afraid to post webmaster/computer-related questions or problems, as our active members are always willing to help when they are able. Interested? Join us.

+ Webmaster Key Forums
|-+ General Discussion
| |-+ Tech Corner
| | |-+ Linux Discussions and Help (Moderator: donecweb)
| | | |-+ Basic guide on using commands in Linux console (Terminal)
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Go Down Stumble Upon! Digg It! del.icio.us! Add to Technorati! ReddIt!  Send this topic Print
Author Topic: Basic guide on using commands in Linux console (Terminal)  (Read 7277 times)
SensoVision
Administrator
Veteran
*****
Posts: 5 857


I'm proud user of Debian GNU/Linux OS


WWW
« on: November 04, 2006, 05:33:51 AM »

Intro:
After my successful move to Debian I was trying to write complete HOWTO on how better move from Windows to Linux,  but since I can't finish it for a long time, I decide to wrote short guide on using commands in console which could help for a person new to this OS use console or perform actions via SSH(could be useful if you use Linux based hosting).
It just my small contribution to big Linux community Smiley
I'm using Debian Etch(Testing branch) so this guide is written in mind with it, but since almost all of these commands are distribution independent they should work for all Linux distributions, and other *nix systems. So here few "secrets" I'd like to share hope they would make your life easier Wink



Few things useful to know:
Ok let's start. Linux is multitasking system, and unlike with Windows, in Linux multitasking starts in console(text mode you see if X Server isn't started). Most distributions set by default to run 6 virtual terminals, you can switch between them ALT+F1ALT+F2, and so up to F6. You can perform in each of these terminals separate task.
ALT+Fn combination would only work if you're in console.
IMPORTANT: if you're running X Server CTRL+ALT+Fn combination should be used in order to get to console, and in order to return back to GUI hit ALT+F7 or CTRL+ALT+F7
Alternatively you can execute most of these commands when you're in X, just use Gnome Terminal(if you're using GNOME as GUI) or konsole if KDE.

“#” and “$” signs were used only to show whenever tool could be used by user or admin only, don't re-post them in terminal.
“$” sign before command will be used for commands which could be executed by unprivileged user.
“#” sign will be used before commands which should be executed by root user



File System Commands:
$ ls
used to show files and directories

$ ls /home
show content of home directory

$ ls -la /etc
adding “l” argument would show content inside /etc directory along with information about permission and modification time, adding “a” would show system files as well.

Tip: if you see too many files which doesn't fit into one screen you can either use “CTRL+ALT+PgUp” and “CTRL+ALT+PgDown” to scroll up and down your console. You can also try to execute list command like this:
$ ls | more
this will let you manually scroll text
or
$ ls | less
scroll text using your cursor and PgUp, PgDown keys. this utility is more handy than more IMHO, but it's not installed by default sometimes, in order to do it in Debian just execute as root this:
# apt-get install less

$ ls -la / > ~/ls_output
it's another way to save output of any command to file, as can you see it's very simple.

$ cat ~/ls_output
list_output will contain all output of ls command and you'll be able to view it with any text editor or just like this.



cd - abbreviation for change directory, as appear from this it let you move across file system.
$ cd /
change current directory to root directory “/” - the highest point of file system.

$ cd ..
move you up to one directory.

$ cd ~
change current directory to your home catalog using tilde "~" in this case would be equal to $ cd /home/your_username. Tilde is just a kind of shortname for current user home directory path.



cp (copy is used to copy files or directories)
$ cp /old_file_path/file1 /new_file_path/file1copy
this will copy file named "file1" from "/old_file_path directory" to "/new_file_path" but with new name "file1copy"

$ cp file1 /new_file_path/
copy "file1" from current directory to "/new_file_path" directory without changing it's name

$ cp /path_to_file/somefile .
if you put dot "." symbol as second argument it will copy file to current directory.

$ cp -R path /newpath
"-R" argument should be added in order to copy directory to another place, if you try to copy one directory to another “cp: omitting directory `path/'” error message will appear.



mv (used to move or rename files and directories)

$ mv oldfilename newfilename
rename oldfilename to newfilename

$ mv /old_file_path/file1 /new_file_path/file2
this will move file named "file1" from "/old_file_path" directory to "/new_file_path" and change it's name to "file2"

$ mv file1 /new_file_path/
move "file1" from current directory to "/new_file_path" directory without changing it's name



rm (removing files or directories)
$ rm file1
will remove file named "file1" from current directory

$ rm -R directory1
remove directory1 from current location, if you not provide -R key this message will appear: “rm: cannot remove `directory1': Is a directory”

TIP: If you remember DOS times and have used programs like Norton Commander, it could be worth to try mc(Midnight Commander) it have similar interface and features and could be helpful tool in learning new FS hierarchy.
to install it on Debian do this as root:
# apt-get install mc

Tip: If you only used Windows previously, Linux file system may confuse you a bit at first as it have different hierarchy. The main reason is that there are no drive letters like: “c:\”, “d:\”, etc. File system in *nix starting with point called root - “/”, all directories are placed under it.
All drives are mounted to point defined by user or program, e.g. your CD-ROM drive in most cases would be mounted to “/cdrom” so “$ ls /cdrom” would show files on your CD disk, floppy under “/floppy”, “/media/floppy”. If no programs for automating mounting are used default mount points could be defined in /etc/fstab file.
All devices e.g. mouse, disks, modem and the rest of devices in your PC are represented by special device files, here you can find more info on this: http://en.wikipedia.org/wiki//dev



Command Auto Completion:
There is very handy tool which help you save your time and fingers from typing extra characters.
E.g. you wish to change directory to /home just input:
$ cd /h
and now it's time to hit TAB button, this should complete your command to "$ cd /home/” isn't that handy? Smiley

Now let's say you don't know exact path, you don't have to waste time executing “ls” to find out what directories are available, just input:
$ cd ~/
and hit TAB again, you'll see all directories inside your user directory, now you just need to input first characters of directory you're looking and hit TAB again Wink
You also can complete commands itself, just try to input any letter and use TAB to see what commands starting with this letter.



Command history:
Another useful method of working in Linux console is utilizing history of commands you've entered. After entering some commands you can just hit cursor UP key. It will show previous command which you can edit and use again, it could really save a time if you use similar command for let's say different files or just made mistake and wish to correct it. Using DOWN key would return you next command.

Another way is to see list of all commands which was entered in console:
$ history
this will display list of last entered commands with ID numbers. To execute one command from the list, simply use ID number before it and put it after “!” sign. E.g. to execute command numbered 12, it's necessary to type:
$ !12



Estimating size of file or directory:
$ du -h somedirectory
above command would show size of directory

$ df -h
this one will display size of all partitions and free space on them



Finding necessary tool:
sometimes it could be tricky to find program you need to perform some task, try this:
$ apropos disk utility
this will display all commands which have keywords “disk utility” in it's description.
If you're using some Debian based distribution e.g. Ubuntu, Knoppix, Xandros, Simple MEPIS, Linspire, etc. you can try following command:
$ apt-cache search disk utility
This would display list of packages in known mirrors. (Tip: Frequently command have same name as package).



Edit text files:
Linux is heavily rely on configuration files in text format, so it's essential to know how to edit files in console. I prefer tool called Nano, to edit some file with it just type:
$ nano /somedirectory/filetoedit
this will open easy to use text editor which could really help sometimes.

If you have installed mc(Midnight Commander)installed you may use editor which comes with it:
$ mcedit /somedirectory/filetoedit
To install both programs mentioned above, execute as root this command:
# apt-get install mc nano


Dealing with archives:
There are a several ways to compress and uncompress files and directories in Linux, I'll show two most universal in my opinion. Let's start with archiving one file:
create some file e.g.:
$ ls > testarc
this would create file with name "testarc"

now let's archive it with gzip
$ gzip testarc
above command will compress file "testarc" and add .gz extension to it, so if you do $ ls you'll see file "testarc.gz" (original testarc file would be removed).

In order to decompress file to original one, simply execute:
$ gzip -d testarc.gz

It's possible to get better compression ratio using .bz2 archives but to achieve this use bzip2 tool. (In Debian just execute as root # apt-get install bzip2).
to compress:
$ bzip2 testarc

to decompress:
$ bzip2 -d testarc

Above way will work for single file only, if you put several files to compress like this:
$ gzip arc1 arc2
you'll get two archived files named "arc1.gz" and "arc2.gz"

If you need to compress directory, you'll need to use tar tool, unlike gzip or bzip2 it wouldn't affect your original file and would uncompress to separate directory or create new archive.
to compress some directories into .gz:
$ tar zcf compressed.tar.gz arcdir1 arcdir2
by this command will created file named "compressed.tar.gz" from "arcdir1" and "arcdir2" directories.
If you add “v” to arguments you'll see output of files added to archive.

to uncompress directory do:
$ tar zxvf compressed.tar.gz

To use .bzip2 tool for getting better compression try this:
to compress:
$ tar jcvf compressed.tar.bzip2 arcdir

to de-compress:
$ tar jxvf compressed.tar.bzip2

So as you can see from above commands “c” argument is used to compress and “x” to decompress, and “z” represent gzip archive and “j” bzip2.

Alternatively you can create archive without compression which could be useful e.g. for backing up data, this would also take less time comparing to using gzip or bzip2:
$ tar cvf compressed.tar arcdir



Finding file:
$ locate filename.txt
this command show location of file at glance because it's search for file using database where files from disk are indexed. There are drawback using this command as if you copy new files to hard drive locate command wouldn't be aware of this changes right away, to re-index new content you may execute:
$ updatedb

$ find /home -name filename.txt
will search "/home" directory for "filename.txt"
this command takes longer to show results but unlike locate it's always have updated info as perform searching in real time

$ which less
used to search for place where executable commands are placed, it will show only commands which are located in the PATH environment variable.



Few useful tools and shortcuts:
$ top
will show list of running processes

$ date
just to see what time is it now

$ uptime
how long your computer is running

$ cat /somefile |grep keyword
if you add "|grep someword" after some command you'll see output limited to strings where word "someword" is present.

Shortcuts:
CTRL+C
stop execution of program

CTRL+Z
terminate program, could help somtimes when CTRL+C wouldn't work.

CTRL+ALT+BackSpace
If you manage to hang up X Server, try following hotkey it would terminate X server and let you restart it once again.



Some useful Debian commands:
# aptitude
this is frontend for apt-get command, it will show you list of installed and available packages and let you remove or install new software easily)

# apt-get install packagename
install some package to your system

# apt-get remove packagename
will remove package

# dpkg-reconfigure packagename
will configure package, for some packages it will also ask questions about options you wish to use for certain package.

# dpkg -i package.deb
last command help you out if you download some file from the web and wish to install it, just point dpkg with “-i” argument to it and you'll get this package installed if all dependencies are met.

# pppconfig
small frontend which will help you configure your modem connection.



That's all for now, hope this short guide would be helpful and sufficient to start using your console.

If you have any questions, suggestions or feedback I'd be glad to hear them. Bug and mistake reports are very welcomed!
It could possibly help me out make this guide better.

BTW if you wish feel free to repost this guide, just remember to place a link to source Wink
« Last Edit: November 04, 2006, 05:53:19 AM by SensoVision » Report to moderator   Logged

Denis
Andy
Administrator
Veteran
*****
Posts: 5 752



« Reply #1 on: November 04, 2006, 11:25:12 AM »

This tutorial looks great but I think you are saying that you are not ready to explain it to Windows users.

Quote
I was trying to write complete HOWTO on how better move from Windows to Linux

Here are my suggestions:

I have watched a few video tutorials lately and I think this is the best format to explain it to windows users.

A great free tool I found for making the video tutorials is wink.

p.s. "videos" in this case means recordings of your computer screen that are played back in a video format such as quicktime etc.

Then a further video on how to have a dual-boot system would be nice so people can switch back into windows while they are still on the learning curve.
« Last Edit: November 04, 2006, 11:31:11 AM by Andy » Report to moderator   Logged

SensoVision
Administrator
Veteran
*****
Posts: 5 857


I'm proud user of Debian GNU/Linux OS


WWW
« Reply #2 on: November 04, 2006, 03:25:42 PM »

Thanks for feedback, Andy! Smiley

This tutorial looks great but I think you are saying that you are not ready to explain it to Windows users.
Actually it's intended mostly for those who already tried Linux and maybe even using it's GUI but wish to know more about how to deal with OS using terminal, console or control PC remotely using SSH. First I was writing big HOWTO about merging to Linux, but it's grow in size and wasn't look complete and easy to understand, that's why I decide to split it up for command guide and for a general advices about how to partition disk and setup various things, I hope that smaller tutorials would be easier to understand and use.

Quote
I have watched a few video tutorials lately and I think this is the best format to explain it to windows users.
I'm not agree. Video tutorials is good for certain things, e.g. I enjoy learning from them things like 3d Modelling when you can see exactly how things are done, but learning programming or how to deal with commands and similar tasks which engage mostly work with text and exclude mouse totally would look at least weird in video tutorial, don't you think? Also although Linux got great GUI lately and have frontends for doing almost any operation with mouse I think that sometimes using terminal is better way of doing things and I guess that some tasks(administrative ones) still couldn't be done in GUI, so if person doesn't wish to deal with text commands at all, probably Linux isn't for him or her. Maybe Mac would work for such people since from what I know it has *nix stability and complete GUI like in Windows.

So particularly for this situation text guide which could be printed on paper would work better IMHO.

Quote
A great free tool I found for making the video tutorials is wink.
I doubt it will work on Linux console anyway, but I thought about using screenshots in my "Move from Windows Guide", just to show what person could expect from installation.
Maybe I'll do such guide but for Hugin, it's open source tool used for stitching panorama and guess that video guide would be best choice for this.

Quote
Then a further video on how to have a dual-boot system would be nice so people can switch back into windows while they are still on the learning curve.
Dual boot would be certainly described as sometimes it's hard to move documents from one place to another or simply leave programs you've get accommodated to.
Report to moderator   Logged

Denis
White Wolf
Key Keeper
Full Member
***
Posts: 180



« Reply #3 on: February 23, 2007, 06:05:31 PM »

I have been wanting to try out Linux but have always been afraid of whiping out my Windows OS because I have no windows OS to reinstall if I don't like Linux (Comp come pre installed)

But I do Have a 80 gig HD that I use as a slave  Is there a way I can Install linux on the slave and boot into it when I want to?
Report to moderator   Logged

donecweb
Administrator
Veteran
*****
Posts: 1 303


DonecWeb


« Reply #4 on: February 23, 2007, 08:40:06 PM »

I have been wanting to try out Linux but have always been afraid of whiping out my Windows OS because I have no windows OS to reinstall if I don't like Linux (Comp come pre installed)

But I do Have a 80 gig HD that I use as a slave  Is there a way I can Install linux on the slave and boot into it when I want to?

Most definitely White Wolf, Linux can be installed into any partition unlike Windows that needs to be in the first partition. I have SimplyMEPIS 6.0 installed on my laptop with both Windows 98 and Windows XP (actually I have 2 copies of SimplyMEPIS on my laptop). On my desktop I also have Windows 98, Windows XP and 2 copies of SimplyMEPIS 6.0. However one copy of SimplyMEPIS 6.0 is on my slave hard drive (80G) while the rest of the Operating Systems (OS) are on the other 80G hard drive. You can also run many if not most Linux distributions (distros) from live CD's. I have tried different distros of Linux and have found SimplyMEPIS 6.0 to be the easiest to switch from Windows. I don't use the Konsole at all except for the desire to try it.
Report to moderator   Logged

DonEc Web

Links and accurate information provide the best answer, while garbage in provides garbage out.
White Wolf
Key Keeper
Full Member
***
Posts: 180



« Reply #5 on: February 23, 2007, 09:48:52 PM »

Thanks for the reply. I do have a linux disk It came with a motherboard I orderd for my computer. I remember I had troubles installing it. I said I had to create a partition or format or something like that That is diffrent than I would normally do when installing windows.

I'll have to try it again as I think I would learn alot about running a linux server by running is as my main OS on my desktop.

Report to moderator   Logged

donecweb
Administrator
Veteran
*****
Posts: 1 303


DonecWeb


« Reply #6 on: February 24, 2007, 01:03:00 AM »

I don't know since I have never run a server. But from what I've heard learning to run a Desktop OS will not help much for learning to run a server. As the tools / commands generally needed to run a server are not available for the desktop as those things are not needed in a desktop.
Report to moderator   Logged

DonEc Web

Links and accurate information provide the best answer, while garbage in provides garbage out.
White Wolf
Key Keeper
Full Member
***
Posts: 180



« Reply #7 on: February 24, 2007, 01:47:13 AM »

well I don't know as I have never ran linux as an OS but most of the comands that Sensovision posted above I do use on my web server via SSH.
Report to moderator   Logged

Pages: [1] Go Up Stumble Upon! Digg It! del.icio.us! Add to Technorati! ReddIt!  Send this topic Print 
+ Webmaster Key Forums
|-+ General Discussion
| |-+ Tech Corner
| | |-+ Linux Discussions and Help (Moderator: donecweb)
| | | |-+ Basic guide on using commands in Linux console (Terminal)

Jump to:  
« previous next »


Our Partners
RelmaxTOP Ranking System Web Hosting RelmaxTOP Ranking System
Staff Sites
12Noon[12Noon Gallery] Andy[Urgentclick]
Tamuril[Tamuril's Digital Art Exhibit] Sensovision
Powered by MySQL Powered by PHP We are hosted by Relmax Inc. |Our Privacy Policy | Sitemap
Powered by SMF 1.1.9 | SMF © 2006-2009, Simple Machines LLC
Forum design by Tamuril © 2005.
Valid XHTML 1.0! Valid CSS!