This is a re-post of topic:
Commands at Konsole: Beginners: 3 parts
http://kubuntuforums.net/forums/inde...opic=3091607.0
See:
Lost Information
http://kubuntuforums.net/forums/inde...opic=3117115.0
Kubuntuforums SQL table corruption
http://kubuntuforums.net/forums/inde...opic=3117108.0
Caution: The text is good, but some links to references may be broken at this time.
- - - - - - - - - - - - - - - - - - - -
Using Commands at Konsole
... for beginners
... in three parts Part 1: this post; Part 2: Reply #1; Part 3: Reply#2
>>> Please post questions in the regular forum (i.e., not here) – Thanks
Tips:
> Work through this 2 or 3 times; practice; check your results using Konqueror or Dolphin.
> Invent your own test files and folder: at Konsole (using text editor kate and mkdir command) or in Konqueror/Dolphin, create text files and folders in your /home or Desktop to practice on.
Part 1 Contents: Navigating
Commands, operators:
pwd, ls, cd, sudo, kdesudo, man, cp, mv, cat, less, >, >> (date, cal, uname, df, blkid)
Topics:
-- Command-line basics, BASH, Konsole: terminal emulator
-- navigating the filesystem
-- home ~, working directory
-- relative & absolute paths
-- root sudo & kdesudo
-- hidden files, one (.) and two dots (.)
-- text editor kate
-- making a file backup
-- standard input & standard output
-- redirection > append >>
-- cat and less
Part 2 Contents
Contents:
-- Create a text file
-- Create a directory
-- Command Summary table: mv, mkdir, cp, rm
-- Making folder backups with cp -r
-- Copying hidden folders (and files)!!!!
-- Navigating is the key: Use cd to get there; then use ls to see what's there
-- Ownership & permissions: the rules
-- chown & chmod: Setting ownership & permissions; diagnosing &fixing problems
-- Mounting filesystems /media, /etc/fstab, mount -a, /etc/mtab
-- Mounting in an emergency: Using a Kubuntu Live CD
-- Flash drive problems: mounting, ownership, permissions, unmounting
Part 3 Contents
- Linux directory tree: man hier
-- History: command history; Up & Down Arrow
-- Alias: make your own command alias name='command'
-- Checksums: md5sum filename
-- Wildcards: * ? [...] {...}
-- Using * in cp, rm: hidden directories (shopt -s dotglob)
-- Removing files and directories: rm, rm -r or rm -R, rmdir
-- Copy files and directories cp, cp -r or cp -R
-- Example: Copy GRUB files using cp
-- Example: Backing up your home data using cp
-- Type of file: file
-- Finding files and folders: cd / && sudo find -name name_of_file
-- Stop the running command (process): Control+C
-- Running processes: top
-- Troubleshooting: dmesg
-- Re-start or turn off computer sudo shutdown -r [-h] now
-- Superblock of filesystem: sudo dumpe2fs -h /dev/sdxn
-- Grep: Search through text for a string
-- Using more than one command at a time: ; && || and pipe |
-- Extract files from an .iso without burning the CD
NEW:
-- Initrd -- opening
-- Tar files: Viewing the contents
-- Chroot into a partition
-- Environment Variables printenv; echo $PATH
-- Example: Working at a prompt: a gparted screenshot
-- NEW (added): Tab completion saves time & typing
-- NEW (added): Empty Trash (at Konsole)
NEW:
-- APT Commands A Summary Sheet
REFERENCES
- - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -
PART 1
Let's get a quick start
Boot into your Kubuntu operating system and open Konsole (keep it open as you read).
in 8.04: K>System>Konsole-Terminal Program
in 8.10: K>Applications>System>Terminal Program (Konsole)
Type each command followed by the Enter key:
Date, time, calendar
For the date & time: date (so, you should type date and press Enter)
For calendar: cal (so, you should type cal and press Enter)
Versions
Kernel version: uname -r (so, you should type uname -r and press Enter)
Kernel version and gcc version (gcc=the GNU compiler used to build the kernel):
cat /proc/version
Linux version/name: lsb_release -a
(hold the Shift key and the minus sign key to get _ . LSB = Linux Standard Base)
KDE version (KDE=K Desktop Environment) (also, open Konqueror, Help>About KDE):
(note the two dashes in front of version)
for KDE 3.5: kde-config --version
for KDE 4: kde4-config --version
Your PC
Hard drives & partitions: sudo fdisk –lu
Drive space: df -h -T
UUIDs are a new way to name devices. Two ways to get UUIDs:
ls /dev/disk/by-uuid/ -alh
blkid
Memory (RAM): free ram
Running processes, in descending order of resource usage: top
Hardware list, on your PC: sudo lshw
Konsole, commands, BASH, virtual terminals, GUI & CLI
You have two ways to communicate with Kubuntu operating system (OS):
The Graphical User Interface (GUI), using the mouse to point and click; manage files and folders with a file manager (Konqueror/Dolphin).
The Command Line Interface (CLI), using the keyboard to type commands at a terminal. This How-To is about the CLI.
BASH is a “shell program” (an interface you use to issue commands to the OS). BASH takes your commands, interprets them, and sends them to the OS. BASH is a command-line interpreter; BASH is one of many such shell programs. A terminal is a direct “physical” interface to the OS. Konsole is a “terminal emulator” (a CLI running within a GUI). BASH runs in the Konsole window. When you open Konsole, you get BASH. You can use Konsole even while you are working in the GUI environment.
Virtual terminals: You also have available seven “virtual terminals” Ctrl+Alt+F1 – Ctrl+Alt+F7. Try them: Control+Alt+F1 (hold down all 3 keys at once; to log in, type your user name and password; to get out, type exit; to come back to the GUI where X is running, open the 7th virtual terminal
Control+Alt+F7.
Command syntax (the grammar of commands)
A command has the form
command -option argument
Note the use of spaces; and the minus sign in front of each option. Sometimes, you will omit options and/or arguments.
Example: df -h -T
A space separates the options -h and -T. You may rearrange and combine options; these are all the same: df -h -T; df -T -h; df -hT; df -Th
A manual: man pages & --help
To learn about a command use the manual pages, like this:
man uname
q to quit To get out of the man page, type q.
The option --help (two dashes) is handy for most commands:
uname –help
To learn about the man pages, type this and then Enter: man man
The command prompt
The command prompt is:
your_name@name_of_computer:~$
(mike@mike-desktop:~$)
It also tells you where you are in the Kubuntu directory tree.
The current working directory is given after the colon sign.
Home directory ~
The ~ sign means your home directory. The symbol “~” stands for “/home/your_name” (your_name means your user name).
To quit Konsole: Type exit, or click Session > Quit. Do that now. Then open Konsole again.
- - - - - - - - - - -
Navigating the Kubuntu directory tree is the key to making this easy
--- Commands: pwd, cd, ls
--- Absolute and relative paths
--- Two dots .. means “parent directory”
Key point:
Use change directory (cd) to get where you want to go in the Kubuntu directory tree.
Then use list files (ls) to see what's there.
File A file is a bunch of data (“bytes”) that belongs together to form a document, a photo, an application, etc. Everything in Kubuntu is a file; even a device (a printer, a hard drive) is a special file.
Directory A directory is a special type of file that contains other files. “Directory” is the technical name; an equivalent term is “folder.” A directory can contain “regular” files and other directories (folders may be contained within folders). When directories are contained in directories (“nested”), they are separated by the slash /: /directory1/directory2/fileA means directory1 contains directory2 which contains fileA. The terms subdirectory and subfolder are often used.
> File & folder names are case sensitive.
MyFile, myfile, and MyFile are different files. Names may contain spaces and punctuation characters, but it's best to limit the punctuation characters to period, dash, and underscore (instead of space).
The working directory is your current location in the Kubuntu directory tree--it tells you “where you are at.” Two ways of knowing the working directory:
Use the command pwd (“print working directory”);
Or, look at your prompt your_name @ name_of_the_computer:~$
The current working directory is given after the colon sign ( : ).
Recall that “~” is a symbol for /home/your_name.
>> Every command you issue is interpreted relative to your current working directory.
Root The topmost directory in Kubuntu is called the root directory and is denoted by the slash: / .
Below root, are several top-level (or root-level) directories. You can see them if you “change directory” into the root directory, then “list” all the files there, like this:
cd /
ls -a
Notice how the prompt changed (after the colon : ) to the root directory, /. The prompt always tells you where you are in the directory tree.
Two primary navigation tools are cd and ls:
the command cd (“change directory”), and
the command ls (“list directory contents”) (also: ls -a, or ls -al).
How to navigate to root, then down the tree to your home directory and Desktop, and back to root again:
cd /
and Enter. (Notice the prompt, the slash /, indicates that the “root directory” is your working directory). List the contents of the root directory by typing
ls
See home? Change into the home directory by typing
cd home
See the prompt change to /home. List the contents of the home directory by typing
ls
See your_name directory? Change into it:
cd mike
See the prompt change to ~. List your home directory contents by typing
ls
See your Desktop? Change into it:
cd Desktop
and list its contents:
ls
At this point, my prompt is mike@mike-desktop:~/Desktop$, where ~ is the same as /home/mike. Thus, your current working directing should be your Desktop. Check it by typing the command
pwd
(“print working directory”); my output is /home/mike/Desktop.
We have navigated from root (/) down to /home/your_name/Desktop. Now let's go back up the tree to the root directory starting from your Desktop.
Two dots ( .. ) means “parent directory,” which is the directory one step up. So the command
cd ..
means “change directory into the parent directory” (of the current working directory).
Here we go:
cd ..
to go from /home/your_name/Desktop up to /home/your_name; check that by typing pwd; again, do
cd ..
to go up to /home; check by typing pwd; again, do
cd ..
to go up to root (/); check by typing pwd. So, you are at the root / directory level.
Go to your home in one step:
cd ~
Now go back to root again in one step:
cd /
and go to your home in one step, another way:
cd /home/your_name
(e.g., cd /home/mike).
And list your home contents:
ls
Paths: Absolute path and relative path
An absolute path starts at root, indicated by a leading (leftmost) slash (/). An absolute path is a sequence of directories that starts at the root directory and ends where you want it to end. If it ends in a file name, the absolute path is called the pathname of the file.
A relative path starts at the current working directory (and never starts with a slash).
> Example: Navigate to your Desktop
Wherever you are in the Kubuntu directory tree, you can navigate to your Desktop using its absolute path by typing cd /home/your_name/Desktop. If you are at the top root level (cd /), you can get to Desktop that way, or you can use a sequence of relative paths: cd home, then cd your_name, then cd Desktop. Each cd command is made “relative” to the current working directory you are in when you issue the cd command. Also, note how the prompt changes as you go.
> Example: List the contents of your Desktop folder.
When you are at the root level (cd /) or anywhere, you can list the directory contents of your Desktop using its absolute path:
ls /home/your_name/Desktop
Troubleshooting two common problems: relative versus absolute paths
1 Using a relative path when you should use an absolute path: Listing directories that aren't there.
Go to the root directory level (cd /), then try to list your home directory using ls your_name:
cd /
ls mike
ls: mike: No such file or directory
The command line did exactly what it should do. Using the relative path called mike, it tried to list that directory; but mike is NOT an immediate subdirectory of root. It is a subdirectory of /home. If you change into /home, there's no problem. Try it with your_name:
cd /home
ls mike
> If you are at root (cd /), to list your home directory in one step, use an absolute path:
ls /home/mike
2 Using an absolute path when you should use a relative path
Start at root, change directory down to your personal home, and list the contents of your Desktop directory:
cd /
cd home
cd mike
ls /Desktop
ls: /Desktop: No such file or directory
What happened? The command did what you told it to do: Since it starts with a leading slash, /Desktop is the immediate sub-directory of root (/), but there is no root-level directory called Desktop (unless YOU created such a strange thing). The expression /Desktop is an incorrect absolute path from root to Desktop. Starting at your home directory, you should have used a relative path to Desktop, like this:
ls Desktop
Another way: If you insist upon using an absolute path to Desktop, use the correct path:
ls /home/mike/Desktop
-- Example: Suppose you are in your home directory:
cd /home/your_name
And suppose you know there is a folder under your Desktop directory called myFolderZ. Starting at your home, to list the contents of myFolderZ, use ls with the relative path Desktop/myFolderZ as follows:
ls Desktop/myFolderZ
Note there is no leading root slash.
Wherever you are in the directory tree, if you want to use an absolute path to list the contents of myFolderZ, do it like this:
ls /home/Desktop/myFolderZ
=> Be careful when you use the leftmost slash in a path. It means “start at root,” and so calls for a proper absolute path.
- - - - - - - - - -
Root
Working with root privileges:
sudo, kdesu (8.04), kdesudo (8.10), sudo -i; sudo su
Rule: When a command requires root privileges, use sudo before the command.
Except...
if it is a graphical application (Konqueror, Dolphin or a text editor), then:
in 8.04 or before, use kdesu (e.g., kdesu konqueror; kdesu kate);
in 8.10, use kdesudo (e.g., kdesudo konqueror; kdesudo kate)
(... then do: Location > Quit to return to your Konsole prompt)
System files: Often, you can open them without sudo, but to edit (& save) the file, you need to work with root privileges. We'll see some examples below with text editor kate.
-- Example: List your drives and partitions: sudo fdisk -lu
(Without sudo, you will only see devices owned by you, not by root.)
-- Example: Get a GRUB prompt: sudo grub
(type quit to get out of GRUB; then type exit to exit Konsole)
A root terminal
Open a terminal as root: sudo -i
See the prompt change from a $ to #. Exit out of root privileges by typing exit.
To get a root prompt when nothing else works: sudo su (type exit to exit)
“Root” has three meanings
1 The root directory of the Kubuntu directory tree (cd / )
2 The root user (or superuser)
3 The home directory of the root user: /root.
To see it, type cd / and then ls and then ls -a root.
In Konqueror: type / (and Enter); then click root.
In Dolphin, click on the red root folder on the left; then in the right panel, click root.
- - - - - - - - - -
The list command ls, hidden files, and the single dot ( . ) (two meanings)[/b]
ls
ls -a
ls -al
-- Syntax of the list command
ls [options] [directory_name]
If you omit directory_name, ls lists the contents of your working directory. Two useful options are -a and -l.
ls -a will list ALL contents, including hidden files & hidden folders.
ls -l will list details--permissions, ownership, size (bytes), date modified.
> Permissions & ownership
To see who owns a file or directory, who has permissions to read, write and execute, use
ls -l directory_or_file_name
-- Single dot (.): Hidden file or directory A hidden file or directory name starts with a dot; e.g., .kde.
Hidden files (and directories) usually contain important system information or your personal configuration settings (but you can make your own by starting a file or folder name with a dot). Change to your home and look. First do:
cd ~
then list ALL files:
ls -a
See hidden files in Konqueror or Dolphin using View > Show Hidden Files.
-- Single dot (.): The single dot ( . ) also means the current working directory but is seldom used. So if you are at /home/your_name, that's the working directory, and ./Desktop means /home/your_name/Desktop. Thus, by using the dot slash ( ./) in front of Desktop, we make Desktop an absolute path.
Summary:
The single dot has two meanings: (1) Hidden files; (2) The working directory.
Two dots .. means the parent directory of the directory you are in now (= the parent directory of the working directory).
- - - - - - - - - -
Text editor Kate: kdesudo kate (8.10); kdesu kate (8.04);
Editing: GRUB and fstab
Making back-ups of system files
To create or edit files at the command line, use a text editor. A popular editor is Kate. You can open kate as a normal user without using root privileges, but then you are not permitted to edit/change any system files.
So, to open Kate as root,
in 8.04, use kdesu kate name_of_file
in 8.10, use kdesudo kate name_of_file
Try this CAREFULLY with the following: Just look, then File > Quit:
> GRUB boot menu: kdesudo /boot/grub/menu.lst
The boot menu is the file menu.lst which is in the directory /grub which is in the directory /boot, and /boot is at the root level (indicated by the leftmost slash /).
> Filesystem table: kdesudo /etc/fstab
The filesystem table is the file fstab in the directory /etc; /etc is at the root level (indicated by the leftmost slash /).
Make a backup sudo cp file file_backup
Before editing (changing) a file, especially a system file like menu.lst or fstab, you should use the copy command cp to make a back-up copy of it.
We'll make a back-up of /etc/fstab and call it fstab_myBackup:
sudo cp /etc/fstab /etc/fstab_myBackup
If you edit fstab and mess it up, to restore fstab, simply reverse it:
sudo cp /etc/fstab_myBackup /etc/fstab
Change directory into /etc and list its contents to see the backup file:
cd /etc
ls
Let's use the remove command rm to remove our backup file from /etc (note that we are already in the directory /etc after issuing cd /etc):
sudo rm fstab_myBackup
Then check that it was removed from /etc:
ls
If we were in some other directory but wanted to delete the backup file, then we'd either use cd /etc to get back into /etc; or we'd just issue the command with the absolute pathname of our backup file:
sudo rm /etc/fstab_myBackup
> We had to use sudo for root privileges because we were changing the contents of the root system directory /etc. Ordinary users do not have permission to do so--you can change your own files and directories in /home/your_name, but not the system's stuff.
- - - - - - - - - -
Standard Input; Standard Output; Re-direction using > and Append >>
To see your text files: cat; less
When using Konsole (or any terminal), the result (output) of your commands is shown (printed) to the screen where you can see it. The screen is referred to as the “standard output” (stdout).
The term “standard input” (stdin) refers to your keyboard.
Re-directing the standard output using the > operator
You can redirect the output of a command to a text file. To do so, use the “re-direction” operator >.
-- Example: fdisk shows your disks and partitions:
sudo fdisk -lu
Now, do it again, but direct the output to a file we'll create and call myFdiskOutput:
sudo fdisk -lu > /home/mike/myFdiskOutput
In place of mike, use your user name. You may change into your home directory to see it (recall, ~ means /home/your_name):
cd ~
ls
(Or, use an absolute path from anywhere: ls /home/mike)
in GUI, use your mouse to open Konqueror/Dolphin and see it.
You can do this with other commands:
cal > /home/mike/calendar
uname -a > /home/mike/kernel_version
df -h -T > /home/mike/Desktop/MyDiskSpace
Naming the text file: The files you created are Plain Text Document files. To remind yourself of that, you may use the .txt extension to name them; e.g., myFdiskOutput.txt. (However, naming files with extensions is optional.)
Relative paths: If you have already changed into your home directory (cd ~) before issuing these commands, then you can use a relative path to redirect the output:
uname -a > MyDiskSpace
or uname -a > MyDiskSpace.txt
df -h -T > Desktop/MyDiskSpace
or df -h -T > Desktop/MyDiskSpace.txt.
Append To append standard output to the end of a text file you already created (and not destroy what is already on your text file), use the "append” operator >>.
-- Example:
cd ~
date > myPCinfoToday.txt
df -h -T >> myPCinfoToday.txt
cat myPCinfoToday.txt
Do you see the date followed by the hard drive information? Use Konqueror/Dolphin to navigate to /home/your_name/myPCinfoToday.txt and see it.
-- Example You can put this result at the end of the kernel_version text you created in the exercise above:
cat myPCinfoToday.txt >> kernel_version
Using cat or less to see your text files
-- cat Use the command cat to view a text file on the screen:
cat /home/mike/calendar
cat /home/mike/MyDiskSpace
If you change into your home directory before issuing these commands, you may omit /home/your_name/:
cd ~
cat calendar
cat MyDiskSpace
Also for system files:
cat /boot/grub/menu.lst
and
cat /etc/fstab
-- less If the file is very large, instead of cat you may use the command less, then use Page Up, Up, Page Down, Down to go through the output on the screen.
G, 1G: Type G to go to the end; 1G to go to the beginning of the text file.
To quit, type q. Try it:
less /etc/fstab
(Type q to quit.)
- - - - - - - - -
End of Part 1
Part 2: Go to Reply #1 next post -->
Commands at Konsole: Beginners: 3 parts
http://kubuntuforums.net/forums/inde...opic=3091607.0
See:
Lost Information
http://kubuntuforums.net/forums/inde...opic=3117115.0
Kubuntuforums SQL table corruption
http://kubuntuforums.net/forums/inde...opic=3117108.0
Caution: The text is good, but some links to references may be broken at this time.
- - - - - - - - - - - - - - - - - - - -
Using Commands at Konsole
... for beginners
... in three parts Part 1: this post; Part 2: Reply #1; Part 3: Reply#2
>>> Please post questions in the regular forum (i.e., not here) – Thanks
Tips:
> Work through this 2 or 3 times; practice; check your results using Konqueror or Dolphin.
> Invent your own test files and folder: at Konsole (using text editor kate and mkdir command) or in Konqueror/Dolphin, create text files and folders in your /home or Desktop to practice on.
Part 1 Contents: Navigating
Commands, operators:
pwd, ls, cd, sudo, kdesudo, man, cp, mv, cat, less, >, >> (date, cal, uname, df, blkid)
Topics:
-- Command-line basics, BASH, Konsole: terminal emulator
-- navigating the filesystem
-- home ~, working directory
-- relative & absolute paths
-- root sudo & kdesudo
-- hidden files, one (.) and two dots (.)
-- text editor kate
-- making a file backup
-- standard input & standard output
-- redirection > append >>
-- cat and less
Part 2 Contents
Contents:
-- Create a text file
-- Create a directory
-- Command Summary table: mv, mkdir, cp, rm
-- Making folder backups with cp -r
-- Copying hidden folders (and files)!!!!
-- Navigating is the key: Use cd to get there; then use ls to see what's there
-- Ownership & permissions: the rules
-- chown & chmod: Setting ownership & permissions; diagnosing &fixing problems
-- Mounting filesystems /media, /etc/fstab, mount -a, /etc/mtab
-- Mounting in an emergency: Using a Kubuntu Live CD
-- Flash drive problems: mounting, ownership, permissions, unmounting
Part 3 Contents
- Linux directory tree: man hier
-- History: command history; Up & Down Arrow
-- Alias: make your own command alias name='command'
-- Checksums: md5sum filename
-- Wildcards: * ? [...] {...}
-- Using * in cp, rm: hidden directories (shopt -s dotglob)
-- Removing files and directories: rm, rm -r or rm -R, rmdir
-- Copy files and directories cp, cp -r or cp -R
-- Example: Copy GRUB files using cp
-- Example: Backing up your home data using cp
-- Type of file: file
-- Finding files and folders: cd / && sudo find -name name_of_file
-- Stop the running command (process): Control+C
-- Running processes: top
-- Troubleshooting: dmesg
-- Re-start or turn off computer sudo shutdown -r [-h] now
-- Superblock of filesystem: sudo dumpe2fs -h /dev/sdxn
-- Grep: Search through text for a string
-- Using more than one command at a time: ; && || and pipe |
-- Extract files from an .iso without burning the CD
NEW:
-- Initrd -- opening
-- Tar files: Viewing the contents
-- Chroot into a partition
-- Environment Variables printenv; echo $PATH
-- Example: Working at a prompt: a gparted screenshot
-- NEW (added): Tab completion saves time & typing
-- NEW (added): Empty Trash (at Konsole)
NEW:
-- APT Commands A Summary Sheet
REFERENCES
- - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -
PART 1
Let's get a quick start
Boot into your Kubuntu operating system and open Konsole (keep it open as you read).
in 8.04: K>System>Konsole-Terminal Program
in 8.10: K>Applications>System>Terminal Program (Konsole)
Type each command followed by the Enter key:
Date, time, calendar
For the date & time: date (so, you should type date and press Enter)
For calendar: cal (so, you should type cal and press Enter)
Versions
Kernel version: uname -r (so, you should type uname -r and press Enter)
Kernel version and gcc version (gcc=the GNU compiler used to build the kernel):
cat /proc/version
Linux version/name: lsb_release -a
(hold the Shift key and the minus sign key to get _ . LSB = Linux Standard Base)
KDE version (KDE=K Desktop Environment) (also, open Konqueror, Help>About KDE):
(note the two dashes in front of version)
for KDE 3.5: kde-config --version
for KDE 4: kde4-config --version
Your PC
Hard drives & partitions: sudo fdisk –lu
Drive space: df -h -T
UUIDs are a new way to name devices. Two ways to get UUIDs:
ls /dev/disk/by-uuid/ -alh
blkid
Memory (RAM): free ram
Running processes, in descending order of resource usage: top
Hardware list, on your PC: sudo lshw
Konsole, commands, BASH, virtual terminals, GUI & CLI
You have two ways to communicate with Kubuntu operating system (OS):
The Graphical User Interface (GUI), using the mouse to point and click; manage files and folders with a file manager (Konqueror/Dolphin).
The Command Line Interface (CLI), using the keyboard to type commands at a terminal. This How-To is about the CLI.
BASH is a “shell program” (an interface you use to issue commands to the OS). BASH takes your commands, interprets them, and sends them to the OS. BASH is a command-line interpreter; BASH is one of many such shell programs. A terminal is a direct “physical” interface to the OS. Konsole is a “terminal emulator” (a CLI running within a GUI). BASH runs in the Konsole window. When you open Konsole, you get BASH. You can use Konsole even while you are working in the GUI environment.
Virtual terminals: You also have available seven “virtual terminals” Ctrl+Alt+F1 – Ctrl+Alt+F7. Try them: Control+Alt+F1 (hold down all 3 keys at once; to log in, type your user name and password; to get out, type exit; to come back to the GUI where X is running, open the 7th virtual terminal
Control+Alt+F7.
Command syntax (the grammar of commands)
A command has the form
command -option argument
Note the use of spaces; and the minus sign in front of each option. Sometimes, you will omit options and/or arguments.
Example: df -h -T
A space separates the options -h and -T. You may rearrange and combine options; these are all the same: df -h -T; df -T -h; df -hT; df -Th
A manual: man pages & --help
To learn about a command use the manual pages, like this:
man uname
q to quit To get out of the man page, type q.
The option --help (two dashes) is handy for most commands:
uname –help
To learn about the man pages, type this and then Enter: man man
The command prompt
The command prompt is:
your_name@name_of_computer:~$
(mike@mike-desktop:~$)
It also tells you where you are in the Kubuntu directory tree.
The current working directory is given after the colon sign.
Home directory ~
The ~ sign means your home directory. The symbol “~” stands for “/home/your_name” (your_name means your user name).
To quit Konsole: Type exit, or click Session > Quit. Do that now. Then open Konsole again.
- - - - - - - - - - -
Navigating the Kubuntu directory tree is the key to making this easy
--- Commands: pwd, cd, ls
--- Absolute and relative paths
--- Two dots .. means “parent directory”
Key point:
Use change directory (cd) to get where you want to go in the Kubuntu directory tree.
Then use list files (ls) to see what's there.
File A file is a bunch of data (“bytes”) that belongs together to form a document, a photo, an application, etc. Everything in Kubuntu is a file; even a device (a printer, a hard drive) is a special file.
Directory A directory is a special type of file that contains other files. “Directory” is the technical name; an equivalent term is “folder.” A directory can contain “regular” files and other directories (folders may be contained within folders). When directories are contained in directories (“nested”), they are separated by the slash /: /directory1/directory2/fileA means directory1 contains directory2 which contains fileA. The terms subdirectory and subfolder are often used.
> File & folder names are case sensitive.
MyFile, myfile, and MyFile are different files. Names may contain spaces and punctuation characters, but it's best to limit the punctuation characters to period, dash, and underscore (instead of space).
The working directory is your current location in the Kubuntu directory tree--it tells you “where you are at.” Two ways of knowing the working directory:
Use the command pwd (“print working directory”);
Or, look at your prompt your_name @ name_of_the_computer:~$
The current working directory is given after the colon sign ( : ).
Recall that “~” is a symbol for /home/your_name.
>> Every command you issue is interpreted relative to your current working directory.
Root The topmost directory in Kubuntu is called the root directory and is denoted by the slash: / .
Below root, are several top-level (or root-level) directories. You can see them if you “change directory” into the root directory, then “list” all the files there, like this:
cd /
ls -a
Notice how the prompt changed (after the colon : ) to the root directory, /. The prompt always tells you where you are in the directory tree.
Two primary navigation tools are cd and ls:
the command cd (“change directory”), and
the command ls (“list directory contents”) (also: ls -a, or ls -al).
How to navigate to root, then down the tree to your home directory and Desktop, and back to root again:
cd /
and Enter. (Notice the prompt, the slash /, indicates that the “root directory” is your working directory). List the contents of the root directory by typing
ls
See home? Change into the home directory by typing
cd home
See the prompt change to /home. List the contents of the home directory by typing
ls
See your_name directory? Change into it:
cd mike
See the prompt change to ~. List your home directory contents by typing
ls
See your Desktop? Change into it:
cd Desktop
and list its contents:
ls
At this point, my prompt is mike@mike-desktop:~/Desktop$, where ~ is the same as /home/mike. Thus, your current working directing should be your Desktop. Check it by typing the command
pwd
(“print working directory”); my output is /home/mike/Desktop.
We have navigated from root (/) down to /home/your_name/Desktop. Now let's go back up the tree to the root directory starting from your Desktop.
Two dots ( .. ) means “parent directory,” which is the directory one step up. So the command
cd ..
means “change directory into the parent directory” (of the current working directory).
Here we go:
cd ..
to go from /home/your_name/Desktop up to /home/your_name; check that by typing pwd; again, do
cd ..
to go up to /home; check by typing pwd; again, do
cd ..
to go up to root (/); check by typing pwd. So, you are at the root / directory level.
Go to your home in one step:
cd ~
Now go back to root again in one step:
cd /
and go to your home in one step, another way:
cd /home/your_name
(e.g., cd /home/mike).
And list your home contents:
ls
Paths: Absolute path and relative path
An absolute path starts at root, indicated by a leading (leftmost) slash (/). An absolute path is a sequence of directories that starts at the root directory and ends where you want it to end. If it ends in a file name, the absolute path is called the pathname of the file.
A relative path starts at the current working directory (and never starts with a slash).
> Example: Navigate to your Desktop
Wherever you are in the Kubuntu directory tree, you can navigate to your Desktop using its absolute path by typing cd /home/your_name/Desktop. If you are at the top root level (cd /), you can get to Desktop that way, or you can use a sequence of relative paths: cd home, then cd your_name, then cd Desktop. Each cd command is made “relative” to the current working directory you are in when you issue the cd command. Also, note how the prompt changes as you go.
> Example: List the contents of your Desktop folder.
When you are at the root level (cd /) or anywhere, you can list the directory contents of your Desktop using its absolute path:
ls /home/your_name/Desktop
Troubleshooting two common problems: relative versus absolute paths
1 Using a relative path when you should use an absolute path: Listing directories that aren't there.
Go to the root directory level (cd /), then try to list your home directory using ls your_name:
cd /
ls mike
ls: mike: No such file or directory
The command line did exactly what it should do. Using the relative path called mike, it tried to list that directory; but mike is NOT an immediate subdirectory of root. It is a subdirectory of /home. If you change into /home, there's no problem. Try it with your_name:
cd /home
ls mike
> If you are at root (cd /), to list your home directory in one step, use an absolute path:
ls /home/mike
2 Using an absolute path when you should use a relative path
Start at root, change directory down to your personal home, and list the contents of your Desktop directory:
cd /
cd home
cd mike
ls /Desktop
ls: /Desktop: No such file or directory
What happened? The command did what you told it to do: Since it starts with a leading slash, /Desktop is the immediate sub-directory of root (/), but there is no root-level directory called Desktop (unless YOU created such a strange thing). The expression /Desktop is an incorrect absolute path from root to Desktop. Starting at your home directory, you should have used a relative path to Desktop, like this:
ls Desktop
Another way: If you insist upon using an absolute path to Desktop, use the correct path:
ls /home/mike/Desktop
-- Example: Suppose you are in your home directory:
cd /home/your_name
And suppose you know there is a folder under your Desktop directory called myFolderZ. Starting at your home, to list the contents of myFolderZ, use ls with the relative path Desktop/myFolderZ as follows:
ls Desktop/myFolderZ
Note there is no leading root slash.
Wherever you are in the directory tree, if you want to use an absolute path to list the contents of myFolderZ, do it like this:
ls /home/Desktop/myFolderZ
=> Be careful when you use the leftmost slash in a path. It means “start at root,” and so calls for a proper absolute path.
- - - - - - - - - -
Root
Working with root privileges:
sudo, kdesu (8.04), kdesudo (8.10), sudo -i; sudo su
Rule: When a command requires root privileges, use sudo before the command.
Except...
if it is a graphical application (Konqueror, Dolphin or a text editor), then:
in 8.04 or before, use kdesu (e.g., kdesu konqueror; kdesu kate);
in 8.10, use kdesudo (e.g., kdesudo konqueror; kdesudo kate)
(... then do: Location > Quit to return to your Konsole prompt)
System files: Often, you can open them without sudo, but to edit (& save) the file, you need to work with root privileges. We'll see some examples below with text editor kate.
-- Example: List your drives and partitions: sudo fdisk -lu
(Without sudo, you will only see devices owned by you, not by root.)
-- Example: Get a GRUB prompt: sudo grub
(type quit to get out of GRUB; then type exit to exit Konsole)
A root terminal
Open a terminal as root: sudo -i
See the prompt change from a $ to #. Exit out of root privileges by typing exit.
To get a root prompt when nothing else works: sudo su (type exit to exit)
“Root” has three meanings
1 The root directory of the Kubuntu directory tree (cd / )
2 The root user (or superuser)
3 The home directory of the root user: /root.
To see it, type cd / and then ls and then ls -a root.
In Konqueror: type / (and Enter); then click root.
In Dolphin, click on the red root folder on the left; then in the right panel, click root.
- - - - - - - - - -
The list command ls, hidden files, and the single dot ( . ) (two meanings)[/b]
ls
ls -a
ls -al
-- Syntax of the list command
ls [options] [directory_name]
If you omit directory_name, ls lists the contents of your working directory. Two useful options are -a and -l.
ls -a will list ALL contents, including hidden files & hidden folders.
ls -l will list details--permissions, ownership, size (bytes), date modified.
> Permissions & ownership
To see who owns a file or directory, who has permissions to read, write and execute, use
ls -l directory_or_file_name
-- Single dot (.): Hidden file or directory A hidden file or directory name starts with a dot; e.g., .kde.
Hidden files (and directories) usually contain important system information or your personal configuration settings (but you can make your own by starting a file or folder name with a dot). Change to your home and look. First do:
cd ~
then list ALL files:
ls -a
See hidden files in Konqueror or Dolphin using View > Show Hidden Files.
-- Single dot (.): The single dot ( . ) also means the current working directory but is seldom used. So if you are at /home/your_name, that's the working directory, and ./Desktop means /home/your_name/Desktop. Thus, by using the dot slash ( ./) in front of Desktop, we make Desktop an absolute path.
Summary:
The single dot has two meanings: (1) Hidden files; (2) The working directory.
Two dots .. means the parent directory of the directory you are in now (= the parent directory of the working directory).
- - - - - - - - - -
Text editor Kate: kdesudo kate (8.10); kdesu kate (8.04);
Editing: GRUB and fstab
Making back-ups of system files
To create or edit files at the command line, use a text editor. A popular editor is Kate. You can open kate as a normal user without using root privileges, but then you are not permitted to edit/change any system files.
So, to open Kate as root,
in 8.04, use kdesu kate name_of_file
in 8.10, use kdesudo kate name_of_file
Try this CAREFULLY with the following: Just look, then File > Quit:
> GRUB boot menu: kdesudo /boot/grub/menu.lst
The boot menu is the file menu.lst which is in the directory /grub which is in the directory /boot, and /boot is at the root level (indicated by the leftmost slash /).
> Filesystem table: kdesudo /etc/fstab
The filesystem table is the file fstab in the directory /etc; /etc is at the root level (indicated by the leftmost slash /).
Make a backup sudo cp file file_backup
Before editing (changing) a file, especially a system file like menu.lst or fstab, you should use the copy command cp to make a back-up copy of it.
We'll make a back-up of /etc/fstab and call it fstab_myBackup:
sudo cp /etc/fstab /etc/fstab_myBackup
If you edit fstab and mess it up, to restore fstab, simply reverse it:
sudo cp /etc/fstab_myBackup /etc/fstab
Change directory into /etc and list its contents to see the backup file:
cd /etc
ls
Let's use the remove command rm to remove our backup file from /etc (note that we are already in the directory /etc after issuing cd /etc):
sudo rm fstab_myBackup
Then check that it was removed from /etc:
ls
If we were in some other directory but wanted to delete the backup file, then we'd either use cd /etc to get back into /etc; or we'd just issue the command with the absolute pathname of our backup file:
sudo rm /etc/fstab_myBackup
> We had to use sudo for root privileges because we were changing the contents of the root system directory /etc. Ordinary users do not have permission to do so--you can change your own files and directories in /home/your_name, but not the system's stuff.
- - - - - - - - - -
Standard Input; Standard Output; Re-direction using > and Append >>
To see your text files: cat; less
When using Konsole (or any terminal), the result (output) of your commands is shown (printed) to the screen where you can see it. The screen is referred to as the “standard output” (stdout).
The term “standard input” (stdin) refers to your keyboard.
Re-directing the standard output using the > operator
You can redirect the output of a command to a text file. To do so, use the “re-direction” operator >.
-- Example: fdisk shows your disks and partitions:
sudo fdisk -lu
Now, do it again, but direct the output to a file we'll create and call myFdiskOutput:
sudo fdisk -lu > /home/mike/myFdiskOutput
In place of mike, use your user name. You may change into your home directory to see it (recall, ~ means /home/your_name):
cd ~
ls
(Or, use an absolute path from anywhere: ls /home/mike)
in GUI, use your mouse to open Konqueror/Dolphin and see it.
You can do this with other commands:
cal > /home/mike/calendar
uname -a > /home/mike/kernel_version
df -h -T > /home/mike/Desktop/MyDiskSpace
Naming the text file: The files you created are Plain Text Document files. To remind yourself of that, you may use the .txt extension to name them; e.g., myFdiskOutput.txt. (However, naming files with extensions is optional.)
Relative paths: If you have already changed into your home directory (cd ~) before issuing these commands, then you can use a relative path to redirect the output:
uname -a > MyDiskSpace
or uname -a > MyDiskSpace.txt
df -h -T > Desktop/MyDiskSpace
or df -h -T > Desktop/MyDiskSpace.txt.
Append To append standard output to the end of a text file you already created (and not destroy what is already on your text file), use the "append” operator >>.
-- Example:
cd ~
date > myPCinfoToday.txt
df -h -T >> myPCinfoToday.txt
cat myPCinfoToday.txt
Do you see the date followed by the hard drive information? Use Konqueror/Dolphin to navigate to /home/your_name/myPCinfoToday.txt and see it.
-- Example You can put this result at the end of the kernel_version text you created in the exercise above:
cat myPCinfoToday.txt >> kernel_version
Using cat or less to see your text files
-- cat Use the command cat to view a text file on the screen:
cat /home/mike/calendar
cat /home/mike/MyDiskSpace
If you change into your home directory before issuing these commands, you may omit /home/your_name/:
cd ~
cat calendar
cat MyDiskSpace
Also for system files:
cat /boot/grub/menu.lst
and
cat /etc/fstab
-- less If the file is very large, instead of cat you may use the command less, then use Page Up, Up, Page Down, Down to go through the output on the screen.
G, 1G: Type G to go to the end; 1G to go to the beginning of the text file.
To quit, type q. Try it:
less /etc/fstab
(Type q to quit.)
- - - - - - - - -
End of Part 1
Part 2: Go to Reply #1 next post -->
Comment