![]() |
ubuntu.com - launchpad.net - ubuntu help
|
|
|||||||
Hello, Unregistered You are browsing a READ only archive of the main support categories pre 4/21/2008. You will not be able to post or reply any threads in this section.
|
|
Absolute Beginner Talk The perfect starting place to find out more about computers, Linux and Ubuntu. |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
May the Ubuntu Be With You!
![]() |
Terminal for Beginners
I've seen time and time again ( and have done it myself ) people give beginners advice that basically is terminal based. Thing is, half the time we forget that to many of these people the Terminal is a scary, unknown thing. So since I have some free time ( yea classes being cancelled! ) I decided that I would write a quick intro to the terminal.
The terminal. Also called "command-line" or Bash (because Bash is the default shell on 90% of distros). Considered an ancient relic of the DOS days by the Windows community, the terminal in Linux is still strong and kicking in the present day. Why? Well because in most cases its just more powerful. You can do tons of things faster in a terminal than you can in a GUI. Its also very customizable. Ask any Guru and chances are they have a huge .bash_aliases file that allows them shorten a string of commands into a few keystrokes, I know I do. But that isn't the aim of this thing. The aim is to give a primer to the terminal. So how do you fire this thing up? In GNOME its under either accessories or system tools. Clicking on it will bring up a window with a prompt, which looks something like this: Code:
kyral@GNUGeneration:~$ Now how do we work this thing? Well my friend its easy. Frankly very easy. I have a directory in my /home called anime. How do I change to it? With the cd (Change Directory) command. Instead of giving an elaborate explination, I'll just show an example and then explain it. Code:
kyral@GNUGeneration:~$ cd anime kyral@GNUGeneration:~/anime$ Code:
kyral@GNUGeneration:~/anime$ ls After War Gundam X Mobile Suit Gundam MS IGLOO Ah! My Goddess Mobile Suit Gundam SEED Ai Yori Aoshi Mobile Suit Gundam SEED Destiny Ai Yori Aoshi Enishi Mobile Suit Turn-A Gundam Azumanga Daioh Mobile Suit Victory Gundam Bleach New Mobile Suit Report Gundam Wing Cowboy Bebop Outlaw Star DearS Rurouni Kenshin Full Metal Panic! Samurai Champloo Full Metal Panic Fumoffu and Specials School Rumble Full Metal Panic! The Second Raid S-CRY-ed Furi Kuri(FLCL) SDF Macross Love Hina Speed Grapher Love Hina Again Trigun Macross 7 Viewtiful Joe Macross Zero Anyway the ls command shows you what is in your working directory. Now do you get the concept? Speaking of working directory, what if you forget? Yah I know the prompt is there, but sometimes you overlook that. Well its easy, its called the pwd(Print Working Directory) command Code:
kyral@GNUGeneration:~/anime$ pwd /home/kyral/anime Code:
kyral@GNUGeneration:~/anime$ cd /usr/bin/ kyral@GNUGeneration:/usr/bin$ Code:
kyral@GNUGeneration:/usr/bin$ cd ~ kyral@GNUGeneration:~$ pwd /home/kyral Code:
kyral@GNUGeneration:~$ cd / kyral@GNUGeneration:/$ ls anime cdrom etc initrd.img media proc srv usr bin debootstrap home lib mnt root sys var boot dev initrd lost+found opt sbin tmp vmlinuz Now some final words before we jump to copying and moving files and whatnot. There are another pair of alias I forgot to mention. ".." refers to the directory directly "above" the working directory. Code:
kyral@GNUGeneration:~/anime$ cd .. kyral@GNUGeneration:~$ Code:
kyral@GNUGeneration:~/anime$ cd ../workspace kyral@GNUGeneration:~/workspace$ Last alias. "." refers to your working directory. Now you may be thinking why do I need that? Well, if you are asked to run an executable, you are going to have to specify the absolute path to it, otherwise its going to go looking in /usr/bin, /usr/sbin, and a bunch of other predefined places. By sticking a ./ infront of the filename, you just did give it the absolute path. Oh, this shouldn't be confused with files and dirs that are named with a . in front, like .bash_aliases. A . in front of the file name means its hidden and won't show up with a normal ls command. You have to use the ls -a command for that. Well this part is done, ON TO PART TWO! Quick Links to the Guide: Part 2: Playing with Files, Tab Completion, Bash Aliases Part 3: Advanced File Ops Part 4: Harnessing the Power of Apt Part 5: Permissions Part 6: Input/Output Redirection and a bit of Sed
__________________
ArchLinux 0.8.0 Associate Member of the Free Software Foundation Last edited by Kyral; December 28th, 2005 at 05:26 PM.. Reason: Added in quick links to the rest of the Guide |
|
|
|
|
|
#2 |
|
Ubuntu French Roast
![]() Join Date: Jun 2005
Location: France
Beans: 6,387
Ubuntu 9.10 Karmic Koala
|
Re: Terminal for Beginners
I like your anime directory
|
|
|
|
|
|
#3 |
|
A Carafe of Ubuntu
![]() Join Date: Jul 2005
Beans: 96
Ubuntu 7.10 Gutsy Gibbon
|
Re: Terminal for Beginners
Hey man, thanks for the info. Being new to all this, the terminal is a bit of a scary thing. I know for me, one of the biggest problems in my understanding is what can be done with the terminal and keeping all the commands either in memory or written down.
-SD- |
|
|
|
|
|
#4 |
|
May the Ubuntu Be With You!
![]() |
Re: Terminal for Beginners
Terminal for Beginners: PART TWO: File fun!
Well, you know how to move about in the terminal, and hopefully it isn't as scary anymore. But all you know how to do is move around. Thats no fun! I also told you that the terminal can be very powerful, but again I haven't shown it. Well file operations are very fun in the terminal. And powerful as well. Here we go again! I assume you remember how to naviagate, so I won't go over that again. There are three basic commands for file operations. cp (Copy), mv (Move), and rm (Remove, basically Delete). cp and mv function pretty much the same way, so I'll cover those first. Okay I'm at home. Time to ls. Code:
kyral@GNUGeneration:~$ ls 14560-firefox-thunderbird.tar.gz 19506-pinux's-tux-cursors-theme-0.3-cur.tar.bz2 2005-08-03--10.05.26 2005-08-03--10.07.23 2005-09-25--20.15.58 20178-Ambidexter.Silver.tar.gz ABC Exams anime Crystalcursors.tar.bz2 cs142 DarkFirePic.png debpacks Desktop document.png ffmpeg-0.4.8-2.rh80.dag.i386.rpm ffmpeg_0.4.8-3_i386.deb Final Fantasy 3.zip finddeps.sh firefox-thunderbird flash freenx-0.4.2.tar.gz GDM-InThisWorld.tar.bz2 gftp_2.0.18-1_all.deb gftp-common_2.0.18-1_i386.deb gftp-gtk_2.0.18-1_i386.deb gftp-text_2.0.18-1_i386.deb gnome-clipboard-daemon-1.0.bin.tar.bz2 GNOME-GNOMEInSilk_1280x1024.png hallelujah.mp3 imacgirl_v3_1280x1024.jpg is400 Jeko_xchat.png keitaroanimeICON.jpg keitaroanime.jpg Manga MCity-Aero-ng-default-1.1.tar.gz mozilla-firefox.png mozilla-thunderbird.xpm mygraph.php MyMusic NVIDIA-Linux-x86-1.0-7667-pkg1.run ONR_Meeting_10052005.doc Oral Presentation Proposal.abw Parallel_Dimensions.jpg pi pics_Full_Metal_Panic_Full_Metal_Panic_fmetalp00.jpg PI.DAT Presentation Proposal.abw programs_sourcecode public.key Purposed ITL Build Software List.pdf q2pres2day2.doc Readme.txt Resume.odt Screenshot-1.png Screenshot.png sdsf.txt Sealab 2021 - 101 - 20021008 - Radio Free Sealab.avi Splash-GNOMEInSilkEvolving2Blurred.png Splash-Linux_splash.png StepMania-3.9-rc3 StepMania-3.9-rc3-linux.tar super_pi super_pi.tar System_Stats_3.0 System_Stats_3.0.tar The_Calling_-_Anime_Wallpaper.jpg thunderbird_icon2.png torrents TransGaming_Drive UbuntuCodeofConduct-1.0.txt UbuntuCodeofConduct-1.0.txt.asc ubuntu-logo.png Ubuntu-tan_01-1280x1024.jpg ut2004 web_sketch.xls wget-log wget-log.1 workspace Copy time! The syntax for cp is Code:
cp [options] <location of file> <where you want the copy to be made> Code:
kyral@GNUGeneration:~$ cp -v Screenshot.png Screenshot2.png `Screenshot.png' -> `Screenshot2.png' Code:
kyral@GNUGeneration:~$ ls 14560-firefox-thunderbird.tar.gz 19506-pinux's-tux-cursors-theme-0.3-cur.tar.bz2 2005-08-03--10.05.26 2005-08-03--10.07.23 2005-09-25--20.15.58 20178-Ambidexter.Silver.tar.gz ABC Exams anime Crystalcursors.tar.bz2 cs142 DarkFirePic.png debpacks Desktop document.png ffmpeg-0.4.8-2.rh80.dag.i386.rpm ffmpeg_0.4.8-3_i386.deb Final Fantasy 3.zip finddeps.sh firefox-thunderbird flash freenx-0.4.2.tar.gz GDM-InThisWorld.tar.bz2 gftp_2.0.18-1_all.deb gftp-common_2.0.18-1_i386.deb gftp-gtk_2.0.18-1_i386.deb gftp-text_2.0.18-1_i386.deb gnome-clipboard-daemon-1.0.bin.tar.bz2 GNOME-GNOMEInSilk_1280x1024.png hallelujah.mp3 imacgirl_v3_1280x1024.jpg is400 Jeko_xchat.png keitaroanimeICON.jpg keitaroanime.jpg Manga MCity-Aero-ng-default-1.1.tar.gz mozilla-firefox.png mozilla-thunderbird.xpm mygraph.php MyMusic NVIDIA-Linux-x86-1.0-7667-pkg1.run ONR_Meeting_10052005.doc Oral Presentation Proposal.abw Parallel_Dimensions.jpg pi pics_Full_Metal_Panic_Full_Metal_Panic_fmetalp00.jpg PI.DAT Presentation Proposal.abw programs_sourcecode public.key Purposed ITL Build Software List.pdf q2pres2day2.doc Readme.txt Resume.odt Screenshot-1.png Screenshot2.png Screenshot.png sdsf.txt Sealab 2021 - 101 - 20021008 - Radio Free Sealab.avi Splash-GNOMEInSilkEvolving2Blurred.png Splash-Linux_splash.png StepMania-3.9-rc3 StepMania-3.9-rc3-linux.tar super_pi super_pi.tar System_Stats_3.0 System_Stats_3.0.tar The_Calling_-_Anime_Wallpaper.jpg thunderbird_icon2.png torrents TransGaming_Drive UbuntuCodeofConduct-1.0.txt UbuntuCodeofConduct-1.0.txt.asc ubuntu-logo.png Ubuntu-tan_01-1280x1024.jpg ut2004 web_sketch.xls wget-log wget-log.1 workspace Code:
rm [options] <path to file> Code:
rm -rf / Code:
kyral@GNUGeneration:~$ rm -v Screenshot2.png rm: remove regular file `Screenshot2.png'? y removed `Screenshot2.png' Now for mv. Again mv behaves just like cp, but it moves the files instead of copy. It also renames them. Yah what? It RENAMES? Think about it. When you rename you basically move the file to one of a different name. Oh I forgot the syntax. Code:
mv [options] <location of file> <place where you want to put it> Code:
kyral@GNUGeneration:~$ mv -v Screenshot-1.png Screenshot2.png `Screenshot-1.png' -> `Screenshot2.png' Keep in mind you can also do this with directories, but chances are you'll need to use the -r option if you are using rm and cp. Now on to a couple other things. I have been keeping a really awesome terminal secret from you, one that makes the terminal really powerful. Its called tab completetion. Now what is that?! Well, if you just type out the first few characters of a file or command or directory and hit tab, the terminal will try to complete the name for you. If its obvious what you want it will instantly complete it for you, saving you a load of typing. If its not, either type a few more characters and try again, OR hit tab once more and it will call up a list of possible completions. Keep in mind for files it will only work for whats in the path you are typing. Confusing. Yah I didn't word it good. Example time. Okay I'm trying to get to /etc/apt/ from ~. So I start typing cd /e and hit tab. Well, from / there is only one thing that starts with e, /etc, so it would fill in. Now I have cd /etc/. I add a to get cd /etc/a and hit tab. Ooops, That isn't unique enough. There must be more than one thing in /etc that starts with a. So I hit tab again. Behold Code:
kyral@GNUGeneration:~$ cd /etc/a acpi/ adjtime alsa/ anacrontab apt/ adduser.conf aliases alternatives/ apm/ at.deny kyral@GNUGeneration:~$ cd /etc/a Code:
kyral@GNUGeneration:~$ ca caesar calibrate_ppa canfield cardinfo cat cal caller captoinfo cardmgr catchsegv calendar cancel cardctl case catman Okay there is one more trick. You wanna see what a file contains? There is a command for that! Assuming you have read permissions, you can do it! (Permissions are another thing entirely). Remember I mentioned something called aliases? Well, I have a file that defines them. You wanna see it? The cat command is your friend. Code:
kyral@GNUGeneration:~$ cat .bash_aliases alias cp='cp -i' alias ln='ln -s' alias mv='mv -i' alias rm='rm -i' alias ..='cd ..' alias ...='cd ...' alias cd..='cd ..' alias cd-='cd -' #alias ls='ls -Cha --color=auto' alias df="df -h" alias h=history alias untgz="tar -xvfz" alias untbz2="tar -xvfj" alias aptsource='sudo gedit /etc/apt/sources.list' alias aptUI='sudo apt-get update && sudo apt-get dist-upgrade' alias aptI='sudo apt-get install' alias aptR='sudo apt-get remove' alias aptS='apt-cache search' alias aptSh='apt-cache show' alias debI='sudo dpkg -i' alias sourcebuild='sudo apt-get source -b' alias depbuild='sudo apt-get build-dep' Well there isn't a case in point because when I did it on a png a bunch of nonsense characters flew past and messed up my terminal. Last thing. You see those sudo commands? Sudo is how we do things in Ubuntu. It grants you Root power for the command that follows it, and then it puts you back as your normal login. Use it, love it.
__________________
ArchLinux 0.8.0 Associate Member of the Free Software Foundation |
|
|
|
|
|
#5 |
|
Dipped in Ubuntu
![]() |
Re: Terminal for Beginners
Kyral - thanks for this very informative info. Can we make this a sticky and also place this in the index of HOW TOs (paging mods)?
K
__________________
"When I'm right no one remembers....When I'm wrong no one forgets.." Registered Linux User#396300 Get Counted Use The Guide After The Guide read the Ubuntu Docs Basic Linux Commands - Check |
|
|
|
|
|
#6 |
|
Just Give Me the Beans!
![]() Join Date: Oct 2005
Location: Altamonte Sprin
Beans: 54
Ubuntu 6.10 Edgy
|
Re: Terminal for Beginners
thanks for the great write up.
|
|
|
|
|
|
#7 |
|
Tall Cafè Ubuntu
![]() |
Re: Terminal for Beginners
This needs to be stickied. Great Job, Kyral! For all us newbies, I say THANK YOU.
![]() |
|
|
|
|
|
#8 | |
|
May the Ubuntu Be With You!
![]() |
Re: Terminal for Beginners
Quote:
__________________
ArchLinux 0.8.0 Associate Member of the Free Software Foundation |
|
|
|
|
|
|
#9 |
|
Tall Cafè Ubuntu
![]() |
Re: Terminal for Beginners
I know, lol. Thanks for doing this!!!
|
|
|
|
|
|
#10 |
|
May the Ubuntu Be With You!
![]() |
Re: Terminal for Beginners
I'll do a Part 3 if there is anything else general like symlinks, which are REALLY cool, or stuff specific to Bash. Actually....I have an idea. I'll put it out after I am done with homework and whatnot.
Preview of Part 3: - Advanced File Ops (Mkdir and Symlinks!) - Bourne Again Fun (I can hear the groans from the experianced people with this one) - Aliases
__________________
ArchLinux 0.8.0 Associate Member of the Free Software Foundation Last edited by Kyral; October 10th, 2005 at 03:20 PM.. |
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|