Announcement

Collapse
No announcement yet.

Commands at Konsole: Beginners

Collapse
This topic is closed.
X
This is a sticky topic.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Commands at Konsole: Beginners

    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 Dolphin.
    > Invent your own test files and folder: at Konsole (using text editor kate and mkdir command) or in Dolphin, create text files and folders in your /home or Desktop to practice on.
    > Get help:
    NEW:
    How to Get Help With a Command from the Linux Terminal: 8 Tricks for Beginners & Pros Alike
    http://www.howtogeek.com/108890/how-...Speed=noscript

    Part 1 Contents: Navigating


    Commands, operators:
    pwd, ls, cd, sudo, kdesudo, man, cp, mv, cat, less, >, >> (date, cal, uname -r, 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

    -- Checking disk space and partitions: fdisk, ls, df, du
    -- Konsole: configure history (# lines to show)

    -- 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 Dolphin, 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 (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 and later), sudo -i; sudo su

    Rule: When a command requires root privileges, use sudo before the command.
    Except...
    if it is a graphical application (Dolphin or a text editor), then:
    in 8.04 or before, use kdesu (e.g., kdesu konqueror; kdesu kate);
    in 8.10 and later, use kdesudo (e.g., kdesudo Dolphin; 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.)

    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 (or sudo ls -a root)
    Then type exit..
    In Dolphin, click on the red root folder on the left; then in the right panel, click root.
    (Or, right-click on root folder, root actions, open in file manager.)


    - - - - - - - - - -

    The list command ls, hidden files, and the single dot ( . ) (two meanings)
    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 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 and later); 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 and later, use kdesudo kate name_of_file

    Try this CAREFULLY with the following: Just look, then File > Quit:

    > GRUB boot menu: kdesudo kate /boot/grub/grub.cfg
    The boot menu is the file menu.cfg which is in the directory /grub which is in the directory /boot, and /boot is at the root level (indicated by the leftmost slash /). In the window grub.cfg -Kate, click the x in the upper right corner to close the window. (This is for GRUB2. Do NOT ever edit grub.cfg directly in GRUB2.)


    > Filesystem table: kdesudo kate /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 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 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 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/grub.cfg
    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 /boot/grub/grub.cfg
    (Type q to quit.)
    - - - - - - - - -

    End of Part 1

    Part 2: Go to Reply #1 next post
    Last edited by Qqmike; Oct 20, 2015, 06:42 AM.
    An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

    #2
    Re: Commands at Konsole: Beginners

    Part 2 Using Commands at Konsole
    text files, file/folder commands, backups, ownership & permissions, mounting, flash drive problems

    ... in three parts Part 1; Part 2: Reply #1; Part 3: Reply#2

    >>> Please post questions in the regular forum (i.e., not here) – Thanks

    Contents:
    -- Create a text file
    -- Create a directory
    -- Command Summary: mv, mkdir, cp, rm
    -- Making folder backups with cp -r
    -- Copying hidden folders (and files): shopt -s dotglob
    -- 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
    - - - - - - - - - -

    Create a text file and directory: Practice

    Create a text file
    In Dolphin, to create a text file, right-click in a blank area and select Create New > Text file. Or, Edit > Create new > Text file.
    To do it at Konsole, type
    kate
    Type some stuff in the empty text file opened by kate; then File > Save, specify the name TestFile and save it in /home/your_name/Desktop, then File > Quit. See it in GUI using Dolphin. See it in CLI using cd ~/Desktop, then list files using ls, as we do next:

    The mv command: move; rename
    Change directory into your Desktop (and remain there as your working directory). Then rename the file TestFile to myFile using the “move” command mv:
    cd ~/Desktop
    ls
    mv TestFile myFile
    The move command mv:
    In a sense, you “move” the file into another name; you can use mv to rename directories; mv is also used to actually move files.

    The mkdir command
    While still in your ~/Desktop directory, using the “make directory” command mkdir, create a directory Folder1, then move myFile into it:
    mkdir Folder1
    mv myFile Folder1
    Make another directory BigFolder and move Folder1 into it:
    mkdir BigFolder
    mv Folder1 BigFolder
    The absolute pathname of myFile is
    /home/your_name/Desktop/BigFolder/Folder1/myFile.

    The cp command, cp -r
    Backups:
    Copy all the contents (including hidden files) of BigFolder to a folder called BigFoldercopy:
    cp -r BigFolder BigFoldercopy
    This command also creates the new directory BigFoldercopy;
    the -r means “recursively” and it ensures that the folder AND everything in it are copied (including hidden files and folders).
    BigFoldercopy is a “backup” copy of BigFolder. You may make up any folder name in place of BigFoldercopy; e.g., BigFolder_backup1. It's also useful to include the date in the folder name.



    See below for more on the copy cp command.

    Commands: remove rm; remove directory rmdir

    Remove (delete) BigFolder using the “remove” command rm. (Make sure you are in the Desktop directory: cd ~/Desktop).
    rm -r BigFolder
    Again, -r ensures that the folder and everything in it are removed.
    If BigFolder were already empty, you could use the “remove directory” command instead, as follows:
    rmdir BigFolder
    If you were not in the Desktop directory when you performed the remove rm command, but were somewhere else in the directory tree, use the full pathname of BigFolder:
    rm -r /home/your_name/Desktop/BigFolder
    If you were at the /home level (cd ~), you could do:
    rm -r Desktop/BigFolder


    SUMMARY of file/directory COMMANDS
    cp, mv, rm, mkdir
    (use man pages to see more; e.g., man cp)


    -- Copy files & directories cp

    cp file1 file2 or cp -i file1 file2
    copies file1 to a file called file2; if file2 already exists, it is overwritten by file1 contents; if file2 doesn't exist, it is created with the contents of file1;
    option -i: interactive mode (you will be informed/asked).
    cp file1 dir1
    copies file1 into directory dir1 (the new file in dir1 is called file1, and so: dir1/file1);

    Folder copying: cp -r dir1 dir2
    copies directory dir1 into directory dir2 (and so yields /dir2/dir1); if dir2 doesn't exist, it is created with the name dir2 and the contents of dir1 including hidden folders and files (but NOT dir1 itself)--thus, in this case, dir2 would be a backup of dir1; the -r = recursive and ensures that all the contents of dir1 are copied down to the lowest level subfolders and files.

    See below for Wildcard and Copying hidden folders (and files) -->

    Wildcard (see Part 3): * means zero or more characters. So dir1/* means all file or foldernames in directory1.
    Assume dir2 exists:
    cp dir1/* dir2
    will only copy files (EXCEPT hidden files) in dir1 (at the top level) into dir2; it will not copy subfolders of dir1; it will not copy dir1 itself.
    cp -r dir1/* dir2
    copies everything (EXCEPT top-level hidden files under dir1) inside dir1, down all levels of subfolders, into dir2; it will not copy dir1 itself.

    CAUTION: See below for using cp with the wildcard * when hidden files and/or folders are involved.


    Backups
    To make a backup of dir1, use: cp -r dir1 dir1_backup.
    Then dir1_backup will be created and will have the same contents as dir1 and will be the backup of dir1. You can make up any name instead of dir1_backup.
    -- Caution: If dir1_backup already exists (e.g., you did mkdir dir1_backup), and you do: cp -r dir1 dir1_backup, then you'll have a copy of dir1 inside dir11_backup: dir1_backup/dir1; that's OK, as long as you understand this.


    The use of * and cp (and -r); IMPORTANT: Copying hidden folders (and files)

    Consider the statement
    cp -r dir1/* dir2
    which copies the contents of directory dir1 into directory dir2.
    To ensure that the wild card * includes ALL files, including HIDDEN files and HIDDEN folders, you might run it this way:

    shopt -s dotglob
    cp -r dir1/* dir2

    Or, edit your file
    ~/.bashrc to include the following two statements:

    # This ensures that * includes hidden folders and files
    shopt -s dotglob

    (Then File > Save, File > Quit)


    Another way:
    cp -rT dir1 dir2
    has exactly the same end result as these two statements:
    shopt -s dotglob
    cp -r dir1/* dir2



    Conclusion about * and cp and hidden files:

    To play it safe, to ensure you always copy hidden folders and files with cp and * (and -r), it might be best to edit your .bashrc to include the two statements:
    # This ensures that * includes hidden folders and files
    shopt -s dotglob


    -- Move, rename files & directories: mv
    mv file1 file2 or mv -i file1 file2
    file1 is renamed file2; but if file2 already exists, its contents are replaced by the contents of file1; option -i: interactive mode (you will be informed/asked)
    mv file1 file2 dir1
    move files file1 & file2 into directory dir1 (dir1 must already exist)
    mv dir1 dir2
    moves dir1 into dir 2 (and so /dir2/dir1) assuming dir2 already exists; if dir2 doesn't exist, dir1 is renamed dir2;
    -- Remove files & directories: rm rmdir
    rm file1 file2 or rm -i file1 file2
    deletes file1 and file2; option -i: interactive mode (you will be informed/asked)
    rm -r dir1 dir2
    removes directories dir1 and dir2 and all their contents (-r = recursive => all their contents)
    rmdir dir1 dir2
    removes dir1 and dir2 assuming they are empty;

    -- Create (make) a directory mkdir
    mkdir dir_name
    creates a directory called dir_name


    - - - - -

    Navigating is the key: cd and ls

    Very important
    : Every command you issue takes effect relative to your current working directory. Your prompt (following the colon sign () or the command pwd (print working directory) both tell you where you are (= your current working directory).

    Example: /home/your_name/folder1/folder2/file1 (= ~/folder1/folder2/file1)
    -- To delete file1, you must be in folder2: use cd to get there. Let's say you are at home (~). Then

    cd folder1
    then cd folder2
    Then to delete file1:
    rm file1
    -- To delete folder2, you must be in folder1: use cd to get there.
    If you are in folder2, get to folder1 using
    cd ..
    (your working directory would be folder2 and the parent directory would be folder1; so cd .. means change directory to the parent directory = folder1; two dots = the parent directory of the working directory)
    To delete folder2:
    If it is already empty (i.e., file1 is deleted), then do: rmdir folder2.
    If it is not empty, then first delete file1(see above), then do: rmdir folder1,
    Before deleting folder2, regardless of where you are in the directory tree, you can get to folder1 using this absolute path:
    cd /home/your_name/folder1

    >>> Using list files ls: a very handy tool. (See man ls)
    Each time you use cd to change into a directory, use ls to see the files and folders in that directory. Then you can work on files you see there, or use cd to change into a subdirectory.

    Summary: Use cd to get there. Then use ls to see what's there.
    - - - - - - - - - -

    Ownership and Permissions Use ls -l to see them; chown & chmod to change them.

    For every file, there are three classes of users:
    The Owner (or User) of the file; The Group that owns the file; and Others--everyone else.
    For a file, and for each of the three classes (owner, group, others), three file permissions are defined: read (r), write (w), and execute (x). Since a directory is a special type of file, everything here applies to directories also.
    r, read
    for a file, you can open it and read it; for a directory, you can list its contents (ls);
    w, write
    file: you can modify it, but can not change its name unless its parent directory has write permission; directory: you can add, delete, and rename files in that directory;
    x, execute
    for a file that is a program (or script), you can run the program; for a directory, you can enter it (change into it using cd) but can not list its contents unless it also has the read permission r.

    Owner: By default, whoever creates a new file or directory is the Owner.
    ls -l: list files, use a long listing format => shows ownership and permissions
    Example: Create myFile as we did above (“Create a text file”), navigate to it, list it:
    cd /home/your_name/Desktop
    ls -l
    -rw-r--r-- 1 mike mike 17 2008-12-17 05:37 myFile

    The first 10 symbols are -rw-r--r--

    The leftmost symbol tells you the type of file. This is a regular file indicated by the “-”.
    (- means a “regular file”; d means directory; l symbolic link; c character device file; b block device file; you can see some of these if you cd /dev and do ls -l)

    The next 3 symbols are read-write-execute permissions for the Owner; then 3 symbols for the Group; and 3 symbols for Others.
    The Owner has rw-: read, write, but not execute; The Group has r--: read, not write, not execute; Others has r--: read, not write, not execute.
    Then mike:mike means the Owner is mike (the leftmost mike); Group is mike (the rightmost mike).
    The file size: 17 bytes. Then the date & time the file was modified. File name: myFile.

    Setting ownership and permissions in GUI
    Open Dolphin as root (kdesudo Dolphin), navigate to the file or directory, right-click, Properties, Permission, make changes, OK. In Dolphin, click the Advanced Permissions button to see all nice choices owner, group, others and read, write, execute. Experiment with this, using a test text file you make. Check it at CLI using ls -l (after you navigate to its directory, like cd ~ or cd ~/Desktop) and in GUI using Dolphin, right-click Properties > Permissions.

    Setting ownership and permissions in CLI at Konsole: Use chown & chmod

    Permissions – numerical mode
    There are 8 possibilities (2*2*2) for read (on or off) - write (on or off) - execute (on or off) permissions on a file or directory (2*2*2 = 8 ). The octal equivalents for these binary numbers are:

    0: ---; 1: --x; 2: -w-; 3: -wx; 4: r--; 5: r-x; 6: rw-: 7: rwx

    Examples:
    777 means that everyone (left-to-right: owner, group, others) can do anything (read, write, execute: rwx).
    740: Owner can do anything, Group can only read, Others can do nothing.
    755: Owner can do anything; Group & Others may read and execute (a program) but can not change it (can not write).
    750: Owner can do anything (read, write, execute); Group can read and execute but not write; Others can do nothing.
    754: Owner can do anything (read, write, execute); Group can read and execute but not write; Others can read but not write and not execute.

    Diagnose PROBLEMS -- Folder & file problems

    --- My directory (folder) is owned by root and/or with wrong permissions: I can't use it!
    Suppose the folder is folder1 (and suppose folder1 is an absolute pathname starting at root (/) or is a folder in your ~ (home) directory (working directory)).
    Ownership: change owner and group to mike
    sudo chown -R -v mike:mike folder1
    sudo is needed because until the command executes, root is the owner of folder1. The -R option means “recursively” so ownership is changed for the directory AND its contents. To see it work, use the verbose option -v. Afterwards, run “ls -l folder1” to see owner:group changed.
    Permissions: If there's a problem with permissions, too:
    chmod -v -R 770 folder1
    changes the entire folder1 directory (including all its contents) to rwxrwx--- (for the owner mike, the group mike, and others).
    --- Your file is owned by root. Change owner & group to mike:
    sudo chown -v mike:mike /home/mike/my_file
    Change permissions, as needed: chmod -v 770 home/mike/my_file
    (no need for -R for a file; only with a directory)
    --- You are owner (& group) of folder1, it contains file1, but you can't change the name of file1.
    You need to change permissions on the folder to allow “write” (so you can change names of files & folders contained in it):
    chmod -v 770 /home/mike/folder1
    We don't use -R because we are only changing permission on the folder, not its contents (i.e., not on files in it); you don't need sudo because you own the folder.
    --- You are owner (& group) of folder1, it contains file1, but you can't change file1.
    You need to change permissions on file1 to allow “write”:
    chmod -v 770 /home/mike/folder1/file1
    --- Make a file executable: to make a file executable: chmod +x program_filename
    (See tuxfiles for this “symbolic” mode)
    --- Change group (to group1): chgrp group1 file_or_directory

    Ownership & permissions:
    FIXING PROBLEMS -- SUMMARY Suppose file1 is contained in folder1.
    -- To list the contents of folder1 (ls -l folder1), you must be in a class (owner, group, others) that has read permissions on folder1.
    -- To change into the folder1 directory (cd folder1), you must be in a class (owner, group, others) that has execute permissions on folder1.
    -- To change the name of file1, you must be in a class (owner, group, others) that has write permissions on folder1.
    -- To read (open) file1 contents, you must be in a class (owner, group, others) that has read permissions on file1.
    -- To change file1 contents, you must be in a class (owner, group, others) that has write permissions on file1.
    -- If you do not own a file or folder, to mess with it you must use sudo: sudo chown; sudo chmod.

    -- Project management
    If you manage a project to read and change some files, one way is this: Put the files in a folder (or folders). Make yourself the folder owner; put the team members in the folder's group. On the folder, give yourself read, write, execute permissions (rwx); give the group read, NOT write, execute permissions (r-x) (so they can cd into the folder but can't change names of files or folders in it). Put the files in the folder. On the files, give yourself read, write, execute (rwx) permissions; give the group read, write, execute permissions (rwx) (so they can work with the files AND change them). Or, give group r-x (not write). Give “others” no permissions on the folder and files (---).
    So, chmod on the folder: 750. On the files: chmod 770 or 750 (your choice).
    - - - - - - - - - -

    Mounting filesystems (/media, /etc/fstab, mount -a, /etc/mtab)

    You can use the command line to mount and unmount devices, such as disk drives and flash drives, and when performing repairs/rescues using a Kubuntu Live CD.

    For example, to write to a flash drive, it must be “mounted.” That means you must “attach” the flash drive's filesystem to a directory (folder) in your Kubuntu filesystem. When you open the Kubuntu directory, you will see the files on the flash drive and can work with them. That Kubuntu directory (folder) is called the mount point for the flash drive's filesystem. Mount points that are already made are in /media. The filesystems that are automatically mounted for you (by default) when you boot into Kubuntu are in the special file /etc/fstab (fstab = filesystem table). To make (force) your system to mount the filesystems in fstab, type the command mount -a or reboot. The filesystems that are actually mounted right now when you are working in Kubuntu are in the special file /etc/mtab. Good news: You can edit /media and /etc/fstab to suit you--adding or removing mount points in /media and in /etc/fstab.

    GUI: To see how directories are mounted:
    Right-click on any directory (folder) in Dolphin, select Properties, and study the panel that pop up to see the mount point in the Kubuntu filesystem for that directory.

    CLI: To see how directories are mounted:
    mount, cat /etc/mtab, cat /etc/fastb, df -hT
    Have a look. Open Konsole, type
    ls -al /media
    Use Kate to look at fstab and mtab (then do: File>Quit), like this:
    kate /etc/fstab
    kate /etc/mtab
    You can also see mtab by typing
    mount
    Another way to see your mount points:
    df -h -T

    To mount a device on the directory dir, the command is:
    mount -t type [options] device directory
    You may have to use sudo:
    sudo mount -t type [options] device directory

    Example: To mount a flash drive
    mount -t ext3 /dev/sdc1 /media/flashdrive
    or, use sudo (which is usually the case):
    sudo mount -t ext3 /dev/sdc1 /media/flashdrive
    (There are no options used in that command. The command mounts the flash drive's directory--partition 1 (sdc1)--on the folder /media/flashdrive in the Kubuntu directory tree. The “t” means type of filesystem, which in this case is ext3.)

    You can often omit the -t, options, type and write simply:
    mount device dir
    (e.g., mount /dev/sdc1 /media/flashdrive)

    => See man page for mount:
    man mount
    (very informative)

    Important:
    The folder /media/flashdrive must already exist before you issue the mount command. If it does not, then simply create a mount point for the flash drive in media as follows:
    sudo mkdir /media/flashdrive
    (You must use sudo to create a (sub-)directory in the system directory /media. You can call the mount point anything you want; we called it flashdrive, but you might use flash1 or usbFD1, etc.)


    Mounting in an emergency: Using the Kubuntu Live CD

    Note: This example was based on GRUB Legacy, not on the new GRUB 2. Although outdated, the example is still valid as an example of using a live CD to mount a filesystem and access and change a file.


    Let's say you must fix the GRUB boot menu file /boot/grub/menu.lst so your PC boots correctly, but you can't boot into Kubuntu to do that. Using the Kubuntu Live CD, open Konsole, type
    sudo fdisk -lu
    to see your drives. Suppose Kubuntu is the partition /dev/sdb3. Let's mount it, then open menu.lst in Kate:
    sudo mkdir /media/sdb3Kubuntu
    sudo mount /dev/sdb3 /media/sdb3Kubuntu
    Thus, in your Live Kubuntu session, when you open the directory /media/sdb3Kubuntu (in Dolphin, or in Konsole), you will see and can access the entire Kubuntu filesystem on partition sdb3.
    Open the boot menu, menu.lst, in Kubuntu on sdb3:
    kdesudo kate /media/sdb3Kubuntu/boot/grub/menu.lst
    (After editing, File > Save, File > Quit)
    Then safely unmount the Kubuntu partition; note the spelling of umount:
    sudo umount /dev/sdb3 /media/sdb3Kubuntu
    Exit the Live Kubuntu session, re-boot your PC to see if you can boot into Kubuntu on sdb3.

    (Notes: sudo is required to make a directory (mkdir) in the system directory /media and to mount or unmount the device /dev/sdb3 on that directory; we made up the directory sdb3Kubuntu to be the mount point, and we made it in the /media directory; we use kdesudo to open Kate because to edit the system file menu.lst we must use root; Kate is a graphical application (you can see it in GUI), so instead of sudo, we use kdesudo; we gave kate the full, absolute pathname for menu.lst file: start at /media/sdb3Kubuntu, which is the Kubuntu partition, then navigate in the Kubuntu root filesystem from root (/) to boot to the directory /grub and then to the file menu.lst)

    Other command forms:
    -- You can shorten the umount command using:
    sudo umount /dev/sdb3 or sudo umount /media/sdb3Kubuntu.
    -- A more proper and complete mount command is:
    sudo mount -t ext3 /dev/sdb3 /media/sdb3Kubuntu
    The -t is “type of file” = filesystem type of /dev/sdb3; here type=ext3. You can use various commands (at Konsole in the Live CD) to find file type:
    df -hT
    blkid # and look for “Type=”


    Mount in GUI: There are also ways in Dolphin to mount filesystems. For example, right-click > Mount.


    APPLICATION: Flash Drives
    Flash drive problems: Ownership, permissions, unmounting

    --- My flash Drive is owned by root and/or with wrong permissions for me!
    (I can't add a folder or file to it or change a file on it.)
    Suppose the flash drive is (mounted as) /media/sdc1.
    (To see how it is mounted, use mount or cat /etc/mtab.)
    To see who owns it:
    ls -l /media

    Ownership: change owner and group to mike
    sudo chown -R -v mike:mike /media/sdc1
    sudo is needed because until the command executes, root is the owner of the folder sdc1. The -R option means “recursively” so ownership is changed for the directory sdc1 AND its contents. To see it work, use the verbose option -v.
    Check it:
    ls -l /media
    (or do: cd /media and ls -l)
    ***=> If you are unable to change ownership as indicated, change ownership of the CONTENTS of the folder /media/sdc1:
    sudo chown -R -v mike:mike /media/sdc1/*

    Permissions: change to rwxrwx---
    sudo chmod -v -R 770 /media/sdc1
    changes the entire sdc1 directory (including (recursively -R) all its contents) to rwxrwx--- (for the owner mike, the group mike, and others).
    Check it:
    ls -l /media
    (or do: cd /media and ls -l)
    Unmounting: When done, unmount the flash drive:
    umount /media/sdc1
    ***=> If you are unable to change permissions as indicated, change permissions of the CONTENTS of the folder /media/sdc1:
    sudo chmod -v -R 770 /media/sdc1/*

    -- My flash drive won't mount
    In GUI, try to right-click on its icon, then Mount.
    In CLI, at Konsole, try:
    sudo mount -a
    then see if it's mounted. Or, as above, create a mount point for the flash drive and use mount; assume it is seen as /dev/sdc1 in Kubuntu, then:
    sudo mkdir /media/flashdrive
    sudo mount -t ext3 /dev/sdc1 /media/flashdrive

    -- My flash drive won't unmount; I get some scary error message!
    Assume you are in your home directory (cd ~). Look in mtab to see how the flash drive is mounted:
    cat /etc/mtab
    Example:
    /dev/sdd1 /media/usbdisk-1 ext2 rw,nosuid,nodev 0 0
    Looks like it is mounted as /media/usbdisk-1. Try to unmount it:
    umount /media/usbdisk-1
    umount: /media/usbdisk-1 is not in the fstab (and you are not root)
    Ooops, I better try this as root:
    sudo umount /media/usbdisk-1
    Then in GUI select “Safely Remove.” => Done!

    Note:
    To see how the flash drive is mounted, you could also use
    df -h -T
    or
    mount

    Note: mount -a
    To mount all devices listed in your filesystem table /etc/fstab, issue this command:
    mount -a
    or
    sudo mount -a

    - - - - - - - - - -

    End of Part 2 Using Commands at Konsole

    Part 3: See Reply #2 below ...
    Last edited by Qqmike; Feb 16, 2015, 07:38 PM.
    An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

    Comment


      #3
      Re: Commands at Konsole: Beginners

      Part 3 -- Neat Stuff and Methods

      Using Commands at Konsole
      ... in three parts Part 1; Part 2: Reply #1; Part 3: Reply#2

      >>> Please post questions in the regular forum (i.e., not here) – Thanks

      Contents:
      -- Linux directory tree: man hier
      -- History: command history; Up & Down Arrow
      -- Alias: make your own command alias name='command'
      -- Checksums: md5sum filename

      -- Checking disk space and partitions: fdisk, ls, df, du
      -- Konsole: configure history (# lines to show)

      -- 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

      -- 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
      -- 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

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

      Linux directory tree
      Command:
      man hier
      See: Filesystem Hierarchy Standard: http://www.pathname.com/fhs/

      Command History
      Command:
      history
      Also, hit Up & Down Arrow keys
      To repeat the recent commands you issued, press the Up Arrow key. Use Up & Down Arrow keys to scroll commands; stop and press Enter to execute the command or edit the command and press Enter to execute it.
      To list all past commands you used at Konsole, use the history command:
      history
      I got 503 lines. Line 502 was
      502 man whatis
      To execute command 502:
      !502
      To Clear History in Konsole, use Edit (tab at top).

      -- Example: Using history Up Arrow with Tab completion to save typing.
      Suppose in your current working directory, you have two folders to delete, folder1xy6zdir7g-1 and folder1xy6zdir7g-2. One way to do it:
      List the files in the working directory (that contains the two files):
      ls
      rm -r fol<Press the Tab key now>
      That returns:
      rm -r folder1xy6zdir7g
      and you then finish it with:
      rm -r folder1xy6zdir7g-1
      and press Enter to remove that folder and all its contents (-r = recursively).
      Then press the Up Arrow key and you'll see your prompt change to its history one command in the past:
      rm -r folder1xy6zdir7g-1
      Before pressing Enter, edit that to read
      rm -r folder1xy6zdir7g-2
      and press Enter to delete that folder.
      Note that
      rm -r fol<Press the Tab key now>
      uses Tab-completion (see toward the end of Part 3 below). It means: type the letters “fol” and press the Tab key (do not type the symbols < or >) and BASH will continue typing for you.


      ''alias'': make up your own command
      The alias command lets you define a new command. Example: ls -alr means list all files in long form and in reverse order. Define a command, say lm:
      alias lm='ls -alr'
      Then, you may use the command lm as you would use ls -alr.

      Checksums: md5sum filename
      After downloading a file (e.g., Kubuntu iso), run the following command to compute the MD5sum:
      md5sum filename
      Compare the result to the md5sum posted at the site.
      -- Example: GParted Live CD
      I downloaded the iso file gparted-live-0.3.9-13.iso to folder /home/mike/Desktop/gpartedCD
      Change into that directory and run the md5sum command:
      cd /home/mike/Desktop/gpartedLiveCD
      md5sum gparted-live-0.3.9-13.iso
      Output:
      dd63e0bf1c6b71add7e5b40656ec84c4 gparted-live-0.3.9-13.iso
      Compare to the value at the GParted site:
      MD5SUMS dd63e0bf1c6b71add7e5b40656ec84c4 gparted-live-0.3.9-13.iso
      They match => the download is good.
      If they did not match, you should return to the site and download the file again.
      This applies in a similar fashion to sha256sum.


      Checking disk space and partitions
      fdisk, ls, df, du

      To check your partitions and their sectors:
      sudo fdisk -lu
      To check disk space, use ls, df, du:
      ls and du: work relative to the directory you issue them from
      df: works from any directory you are presently in

      ls -al See man ls.
      List all files (in the present working directory) in long form and shows their size. A quick way to check things. First, change directories (cd) into the directory (folder) you wish to check.

      df -hT See man df.
      A quick way to see your mounted filesystems, the space Used and Available, your root (/) and /home directories. You can issue this from any directory and get the same result.

      du See man du.
      Shows you the disk usage of each file. Change into the directory you wish to check. du will check it and subdirectories recursively. So you run it, study the output, pick a directory from the output to investigate further, change directories into that directory (using cd), run du again, study the output, etc. Try these now, first changing into the root directory (cd /), then after changing into your home directory (cd ~ , or: cd /home/your_name).
      du -sh is a summary (-s) only, in human readable form (-h)
      du -h shows directory details (and subdirectories).
      du -ah shows (all = -a) files
      See next topic about configuring Konsole.

      Konsole: configure history (# lines to show)
      When you issue a command that prints a large number of lines, you can scroll up to see lines that have scrolled off the screen; or use Up arrow or Page Up. The default is to show you 1000 lines this way. If you need more (e.g., using du in certain cases), you can configure Konsole to show them all:
      Open Konsole, Settings, History, History Configuration, Set Unlimited, OK.


      Wildcards * ? [...] {...}
      A wildcard is a special character you can use in a filename.
      * means zero or more characters.
      ? means exactly one character; ?? means two characters; etc.
      [characters] means exactly one character listed:
      A character may be a letter (a-z, A-Z) or a numeral (0-9).
      You can use a range, like d-k or 2-5.; or a list like [defghijk] or [2345].
      [!characters] means any character that is not listed.
      [!0] means any nonzero character.
      {word1,word2,word3} means exactly one word listed.
      -- Example: cd ~/Desktop && ls K*[0-9]
      means change to your Desktop directory, THEN list all files that start with a K and end with a numeral between 0 and 9.
      -- Examples: See Removing files and Copy files below:

      IMPORTANT:
      Using * in cp, rm: hidden directories (shopt -s dotglob)
      To ensure that the wild card * includes HIDDEN folders and files, include the following statement in your file ~/.bashrc:
      shopt -s dotglob
      Or, use it like this:
      shopt -s dotglob
      cp -r dir1/* dir2
      Or, use this statement (which has the same end result):
      cp -rT dir1 dir2
      (to copy ALL contents of dir1 into dir2).

      Removing files and directories: rm, rm -r (or rm -R), rmdir
      cd dir1
      rm *
      means change into directory dir1 and remove every file. It will not remove any subdirectory of dir1.
      rm -r *
      means remove all files and (sub)directories recursively: it will empty ALL contents of dir1; but it does not remove dir1 itself. Thus dir1 still exists but is empty.

      -- To remove dir1 itself:
      After issuing cd dir1 and rm -r *, then dir1 is empty, so you can change to its parent directory and remove dir1:
      cd ..
      rmdir dir1
      The command to remove directory, rmdir, works only if the directory to be removed is empty.
      -- To remove dir1 and all its contents in one step, you must first be in its parent directory, then issue
      rm -r dir1
      That removes dir1 and all its contents (files and subfolders and their contents) from the filesystem.


      Copy files and directories cp, cp -r
      cp -r folder1/* folder2
      means copy all the contents of folder1 into folder2 but NOT folder1 itself.
      cp folder1/k*.txt folder2
      means copy all files in folder1 that begin with a “k” and have the .txt extension into folder2.
      cp folder1/*kubuntu* folder2
      means copy all files in folder1 that have the word “kubuntu” in their filename into folder2.

      > You can use wildcards with other commands (e.g., mv, ls) just as we did with rm and cp.

      Example: Copy GRUB files
      In Kubuntu, the (13 or so) GRUB files are at /boot/grub. Suppose you wish to set up /boot/grub in another directory called targetdir. Assume targetdir is either an absolute path or that it is in your current working directory. E.g., targetdir may be the first partition of a flash drive mounted as /media/sdc1. So the goal is: targetdir/boot/grub (with all the GRUB files copied into this new grub directory). Here's how.
      (Assume you own the flash drive and have all permissions; if not, you must use sudo in front of commands.)

      Solution #1: The safe way.
      mkdir targetdir/boot
      mkdir targetdir/boot/grub
      cp /boot/grub/* targetdir/boot/grub
      copies all the files in /boot/grub (of Kubuntu) into the directory targetdir/boot/grub.
      Note: Change directory (cd) and list files (ls) to check your results, like this:
      cd targetdir/boot
      ls
      cd grub
      ls

      Solution #2
      Create a boot directory in the targetdir and copy the grub folder and all its contents into it:
      mkdir targetdir/boot
      cp -r /boot/grub targetdir/boot
      (or cp -r /boot/grub/ targetdir/boot)
      The result will be targetdir/boot/grub (and all the files in grub). Since there is no grub directory in targetdir/boot, a directory called grub is created, and the grub files (from /boot/grub in Kubuntu) are copied into it. The recursive option -r means to copy the folder grub and its contents.

      Caution: Subtleties
      If you omit mkdir targetdir/boot, and then do: cp -r /boot/grub targetdir, you will get targetdir/grub (and the GRUB files copied into it)--you will NOT get targetdir/boot/grub! Also:
      cp -r /boot/grub grub
      will create a new folder called grub (in the working directory) and copy grub files into it; however,
      cp -r /boot/grub boot/grub will NOT create boot and then create boot/grub!


      Example: Backing up your home data using cp
      -- Assume your OS is messed up and you will re-install it or delete it; but your /home/your_name is in the same partition as Kubuntu. Use a Live CD; if Kubuntu is mounted as /media/sdb2 and your flash drive as /media/sdc1, to copy your home to a flash drive:
      sudo cp -r /media/sdb2/home/your_name/* /media/sdc1/
      (/dev/sdc is also correct, without the ending slash)
      -- If you are able to boot into Kubuntu, to copy all directories and files in your home to a flash drive (sdc1):
      cd /home/mike
      cp -r * /media/sdc1

      Type of file: file filename (the command is file; the argument is filename)
      Tells you the type of file that filename is.
      Examples of file types: ASCII text, data, application, JPEG image data, C program text, block special, data, x86 boot sector, Linux/i386 ext2 filesystem, x86 boot sector, extended partition table, Linux/i386 swap file.

      Very Useful:
      Finding files and folders (see the symbol && below)
      Command:
      cd / && sudo find -name name_of_file
      Ex: cd / && sudo find -name device.map
      Output: ./boot/grub/device.map
      (the leading dot means “working directory” = root = / (since we did change into root using cd /))
      Specify a directory to search by placing the directory name after "find" and before "-name":
      Ex.: In GRUB Legacy, cd / && sudo find /boot -name stage1
      Output: /boot/grub/stage1

      Stop the current running command

      Ctrl-c: Stop the current running command
      You can use this if you started a command running for a long time and you wish to terminate it AND you know it is safe to do so and will not mess up your system.

      Running processes: top
      Command top shows the running processes in descending order of resource usage. Leave that window running. When the system "hangs," top shows the resource hogs.

      Troubleshooting (e.g., kernel panic): dmesg
      dmesg > reportfile
      will print the results to the test file reportfile in the working directory.
      Here's another:
      tail -20 /var/log/dmesg
      will print the last 20 lines of the log dmesg to the screen;
      tail -20 /var/log/dmesg > mesg_report.txt
      will print the last 20 lines of the log dmesg and redirect the output to a text file called mesg_report.txt.


      Re-start or turn off computer
      sudo shutdown –h now (for power off, halting)
      sudo shutdown –r now (for rebooting)


      Using more than one command at a time
      semicolon ; && || and pipe |

      command1 ; command2
      means to execute command1 then execute command2.
      command1 && command2
      means to execute command1; if and only if command1 executes successfully, then execute command2.
      Example: see “Finding files and folder” above.
      command1 || command2
      means execute command2 only if command1 fails.
      Note: the symbol | is above the “\” symbol on your keyboard (vertical “pipe” symbol); here, you need two of them: || . (So: Shift+|)

      Pipe |
      When you need the output from command1 for the input into command 2, then you would use the pipe operator '|'. You can send the output of a command to be the input of another command using a pipe symbol | , and doing so is called “piping.” The syntax for piping:
      command1 | command2
      -- Example:
      To print the Master Boot Record of drive sda to the screen:
      dd if=/dev/sda bs=512 count=1 | hexdump -C
      The standard output of the dd command is the input for the hexdump command (see man hexdump).
      See “Example: Piping, grep -i, cat, redirection >” below.

      Search through text for a string: grep
      Command: grep "some string" somefile
      -- Example: grep "Linux" /home/mike/testfile
      will search for the string Linux in the file testfile. Command grep examines each line of data it receives from standard input and outputs every line (to standard output = the screen) that contains a specified pattern of characters. See man grep.
      See next Example.

      Example: Piping, grep -i, cat, redirection >, less
      See Part 1 for redirection > and cat and less
      -- Exercise:
      Navigate to your Desktop (cd ~/Desktop), and use Kate to make a file (see Part 2) called MyFile.txt, and include, say 15 or 20 lines (press Enter after each line) of any text you wish to type, but include the word Dog on two lines, the word dog on one line, and the word DOG on one line. You are still in /home/your_name/Desktop.
      Use cat to see the file:
      cat MyFile.txt
      Use less to see it (then press q to quit):
      less MyFile.txt
      The command grep is used to search a file for a string of text that you specify (see man grep). Let's display your file on the screen and pipe that output (standard output) to become the input to the command grep, and we'll use grep to search for the word dog:
      cat MyFile.txt | grep dog
      (I got 1 line: )
      dog is king
      Now search for Dog:
      cat MyFile.txt | grep Dog
      (I got 2 lines: )
      Dog is here now!!!
      Dog is also here at the same time
      Search for DOG:
      cat MyFile.txt | grep DOG
      (I got 1 line: )
      DOG is in this line of text

      Command grep is case sensitive!
      You can use the option -i to make grep case insensitive as it searches your file for various forms of dog:
      cat MyFile.txt | grep -i dog
      This time I got all 4 lines:
      dog is king
      Dog is here now!!!
      DOG is in this line of text
      Dog is also here at the same time

      -- Pipe: redirect to a text file
      To have a text file copy of your search results, you can redirect the output of grep to a file in your Desktop (since that's the working directory) called, say, dogFile:
      cat MyFile.txt | grep -i dog > dogFile
      (In place of dogFile, you could specify any path, like an absolute path to /Folder1/Folder2/myDogFile:
      cat MyFile.txt | grep -i dog > /Folder1/Folder2/myDogFile)
      => See Part 1 for redirection >.

      Extract files from an .iso: Access iso files without burning the CD
      Here's how, using an example.
      The goal is to copy some files off an iso file WITHOUT having to burn the iso to make a Live CD.
      Download the iso file to your Desktop folder.

      (=> If it's a tar.gz file or similar, get the iso by right-click, Extract Here, or use ARK under K > Applications > Utilities > Archiving Tool (ARK).)

      Example: Let's say the file name is kubuntu-8.10-desktop-i386.iso and it's in my Desktop folder:
      /home/mike/Desktop/kubuntu-8.10-desktop-i386.iso

      Make a directory /media/test for your mount point
      sudo mkdir /media/test

      Mount the iso on the directory /media/test: this is the KEY command!
      sudo mount -t iso9660 -o loop /home/mike/Desktop/kubuntu-8.10-desktop-i386.iso /media/test

      You may change directories (cd /media/test) and list all the files (ls -a) to see what's there.
      Or, use the absolute path: ls -a /media/test
      Now you may copy (cp or cp -R) files and folders in /media/test.
      Assume you copy them into a new directory /tmp/new_folder. (Using mkdir & cp)
      Then change the ownership so you (mike) can have these files and then unmount it:
      sudo chown -R mike:mike /tmp/new_folder
      Unmount /test:
      sudo umount /media/test
      If you have to invoke root, use sudo (as I have above, when it was necessary).
      Now you (the owner) may do whatever you wish with the files & folders in /tmp/new_folder.


      Initrd--opening

      Sometimes you may have to examine or even patch the important file initrd, especially if doing work with bootloaders, kernels, building flash drives or live CDs and live USBs. Here's how to open an initrd.gz file. To avoid working as root directly with your files under /boot (including initrd), let's illustrate this by working safely on your Desktop. Sometimes, initrd may be under a Casper directory (e.g., on a live CD). As an example, you may first open an iso file, then access an initrd contained in a folder of the iso. See topic above for opening an iso.
      Tip: As you go along, use your GUI and file manager to see what's happening after each command.
      Note: In this example, initrd.gz represents your initrd file. For example, initrd.gz may be initrd.img-2.6.24-23-generic.
      Caution: Be real careful messing with the important system file initrd! You can easily break your system.

      > Create a safe place to work.

      Log in to your working Kubuntu operating system.
      On your Desktop, create a folder to work in, say work_here:
      Right-click on Desktop, Create New > Folder, and type work_here for “Enter folder name.”
      Alternatively, do this at Konsole, at your home directory prompt:
      mkdir /home/your_name/Desktop/work_here

      > Copy the initrd file to work_here
      You can do this in GUI or at Konsole. You may want to create a backup for the original initrd file, call it initrd.gz.backup.
      At Konsole:
      cp /path/to-initrd/initrd.gz /home/mike/Desktop/work_here
      (e.g., cp /boot/initrd.img-2.6.24-23-generic /home/mike/Desktop/work_here)

      > Open Konsole and get ready to work.
      K > System > Konsole. To become root, type
      sudo su
      Navigate to the folder work_here:
      cd /home/mike/Desktop/work_here

      > Extract initrd.gz (it is a compressed file and has been compressed by the algorithm called gzip).
      Type the following command to do this:
      gzip -dc initrd.gz | cpio -i

      Now if you look in the folder work_here, you'll see all the extracted files and folders.
      (You can do so in GUI or at Konsole by typing ls -al )

      > Edit the broken file that's causing the problem.
      You should still be in the folder work_here. Suppose that file is /somefolder/somefile.
      Open the file in kwrite (or kate):
      kwrite somefolder/somefile
      Make your changes to somefile, then File > Save, File > Quit.

      > Zip the new initrd.gz file.
      Still at Konsole, you should still be in the folder work_here. Issue this command at Konsole:
      find . | cpio -o -H newc | gzip -9 > initrd.gz
      (Note This reads as follows: find then space then a period then space then the vertical pipe bar etc--don't omit the "dot" after find then space)

      > Put it back together in its original location.
      cp initrd.gz /path/to-initrd/initrd.gz

      (Note: You should still have a root prompt, and you MAY need it because you are modifying initrd in some boot folder (or Isolinux or Caper folder). Again, to see what's going on or if you get stuck on something, you can always check things in GUI, starting by opening Konqueror as root in another instance of Konsole by typing the command kdesudo konqueror, or if you wish, kdesudo dolphin.)

      References
      cpio
      http://www.gnu.org/software/cpio/manual/cpio.html
      gzip
      http://www.gnu.org/software/gzip/man...ip.html#Sample

      [End of topic: Initrd -- opening]


      Tar files: Viewing the contents
      Software is often distributed as a gzipped tar file compressed with gzip. (Linux/Unix: “tar” = “tape archive”). These files have extensions tar.gz or .tgz. To view the directory of such a file:
      tar -tzvf name_of_file.tar.gz | less
      For more info: man tar
      Example: Super Grub Disk source code
      tar -tvf public_super_grub_disk_source_code_0.9774.tar.bz2 | less
      (For bz2, don't use the option z) We piped the output to less.
      To navigate less output:
      Use Page Up, Page Down, Up, Down
      G (go to the end of the file)
      1G (go to the beginning)


      Chroot
      To “chroot into a partition” is to enter the partition with root privileges (“as root”). (The root directory is set equal to the partition.)
      Here's how:
      Let's say Kubuntu is in partition sda2, something is broken there, and you need to use your Kubuntu Live CD to chroot into sda2 and fix the problem. From the Live Kubuntu CD at Konsole:
      sudo mkdir /media/fixthings
      sudo mount /dev/sda2 /media/fixthings
      sudo chroot /media/fixthings
      => Now you are “in” sda2 “as root” and can work from there as if you were actually booted into it. The command prompt is a root prompt “... :/#” You can enter the commands you will use to fix the problem in sda2. When done, type exit to leave the root prompt:
      exit
      Now the prompt is a regular, non-root prompt “... :~$”
      To be safe, unmount the partition:
      sudo umount /dev/sda2 /media/fixthings
      => CAUTION Do not use chroot unless you know what you are doing; you can damage your Kubuntu filesystem if you make a mistake while using chroot.


      Environment Variables printenv; echo $PATH
      Environment variables are used by various processes running while you are logged into your Kubuntu account. To see yours, type
      printenv
      and you will notice many familiar environment variables, such as PWD (present working directory), HOME (your home), USER (you), etc. Notice SHELL=/bin/bash, which tells you that the bash program is in directory /bin.
      An important environment variable is PATH; mine says:
      PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
      You can also see PATH by typing
      echo $PATH
      PATH specifies the places the system looks when you try to run a program (an executable file). The system starts from the left, /usr/local/sbin, and works to the right until it locates the program you are trying to execute. Open Dolphin, have a look at these places. For example, navigate to /bin where you can see bash and a bunch of familiar commands (executable programs, indicated by a gear). The command date is one such program.
      Run (execute) date in two ways (in Konsole):
      date
      /bin/date
      Because (the small utility) date is in your environment variable PATH, you can type simply “date” (and not /bin/date) to execute it.
      => If you are unable to execute a program you KNOW you have (and get “Command Not Found”), it is because the location of the program is not included in your PATH environment variable.
      Changing Path, adding /new/folder/here to it
      :
      PATH=/$PATH:/new/folder/here


      Working at a prompt in an application: a gparted screenshot example

      Now and then, in an application, you'll find you need a command line to do something. Here's an example. Suppose in GParted Live CD or in gparted (from Kubuntu), you need a screenshot. While in GParted, take the screenshot following directions there, and it will be saved in /root for you. That is the /root within the GParted program (on disk or in RAM), NOT in your Kubuntu filesystem. Here's a way to get the screenshot onto your flash drive:
      In GParted, click Terminal icon. You get a prompt, like this:
      root@debian:~#
      Make sure you are in root and ls files to see the screenshot (called gparted.jpeg):
      cd /
      ls
      Output: gparted.jpeg
      Plug a flash drive into a USB port and make GParted see it:
      GParted (tab at top left) > Refresh Devices (and check the drop-down list at upper right of GParted screen). Suppose the flash drive is sdc1. Make a directory for mounting the flash drive:
      sudo mkdir /root/flashdrive
      sudo mount /dev/sdc1 /root/flashdrive
      Copy the screenshot into the flash drive:
      cp gparted.jpeg flashdrive
      Check that it is in the flash drive:
      cd flashdrive
      ls
      gparted.jpeg
      Unmount the flash drive:
      sudo umount /dev/sdc1 /root/flashdrive
      When you exit GParted, the screenshot will be on your flash drive as the file gparted.jpeg.


      NEW, Added:

      Tab Completion – Typing made easy while navigating

      When typing file and directory names, you can sometimes use tab completion to make typing easy and fast.
      Suppose you have the following directories:
      /home/your-name/Desktop/xyzTest-Folder.21t-D3.26linux/whyld47yt-69.3G
      along with many other files & folders in the Desktop folder. To “drill down” to the file or folder whyld47yt-69.3G, try using tab completion:
      Starting at your home (cd ~),
      cd Desktop
      and list files to see what's there:
      ls
      where you see the folder xyzTest-Folder.21t-D3.26linux
      To change directory into the folder xyzTest-Folder.21t-D3.26linux, try this:
      cd xyz<Press Tab key now>
      (but do not type the symbols < or >)
      You should see that the rest of the folder name is automatically completed for you after you hit Tab.
      To accept it, press Enter. To see what's in the folder xyzTest-Folder.21t-D3.26linux, list files again:
      ls
      You'll see all the files and folders contained in xyzTest-Folder.21t-D3.26linux, including the folder whyld47yt-69.3G, so again type
      cd wh<Press Tab key now>
      and see the Tab-completion take place automatically:
      cd whyld47yt-69.3G
      and press Enter to accept it.

      Tab-completion choices
      Suppose two files (or folders) have similar names; e.g., whyld47yt-69.3G and whyld47yt-610.3G.
      If you type
      cd why<Press the Tab key>
      you'll get:
      cd whyld47yt-6
      at which time you may type either 9 or 10 and press Tab again to complete the name.

      Editing Tab-completion entries
      After using Tab-completion, you may edit the name that results before pressing Enter to accept it. You may also use Tab-completion more than once—even repeatedly—to “get” the full name you are after in a command line.

      Navigating: Thus, use cd, ls, and tab completion to navigate quickly and easily through the filesystem.

      NEW, Added:

      Empty Trash
      It sometimes happens that you are unable to “Empty Trash Bin.” Or, you delete something, but it doesn't appear in the Trash Bin. Such items are here:
      /home/your_name/.local//share/Trash
      where you will see two folders: files and info. The directory called files contains deleted folders/files; and info contains information about such deleted items.
      You can manually empty files and info as follows:
      cd /home/your_name/.local//share/Trash
      ls
      files info
      sudo rm -r files/*
      sudo rm -r info/*

      In fact, you may remove the entire folders files and info and they will be re-created as they are needed; i.e., as you delete items:
      sudo rm -r files
      sudo rm -r info


      NEW

      APT: Advanced Packaging Tool

      -- APT Commands -- A Summary Sheet

      APT: Advanced Packaging Tool-- APT Commands -- A Summary Sheet

      Help: man apt-get

      --> Use sudo with apt commands.

      Sources (of packages)
      /etc/apt/sources.list –> where to look for and get packages
      All Debian packages: https://www.debian.org/distrib/packages

      All packages on your system: dpkg -l (This will be a very long list!)
      Print this list to a file, from your home directory (cd ~): dpkg -l > MyListDebian.txt

      sudo apt-get update
      This refreshes the package list and info from the repositories.
      Run this after editing source.list and before using apt-get.

      sudo apt-get upgrade
      This installs the newest versions of all packages currently installed.

      sudo apt-get dist-upgrade
      "dist-upgrade in addition to performing the function of upgrade, also intelligently handles changing dependencies with new versions of packages; apt-get has a "smart" conflict resolution system, and it will attempt to upgrade the most important packages at the expense of less important ones if necessary." (man apt-get) (Note: dist-upgrade does not upgrade your distribution to a higher version; e.g., it will not upgrade your Kubuntu 12.04 to 14.04.)

      --> See man apt-get for details.

      General (use sudo before the commands)

      First:
      apt-get update
      Search:
      apt-cache search package_name
      Install:
      apt-get install package_name
      Remove:
      apt-get remove package_name
      apt-get --purge remove package_name
      (--purge: deletes configuration files, too)
      Clean:
      apt-get clean
      (cleans /var/cache/apt/archives where packages are first downloaded)
      apt-get autoclean
      (removes old package files, out of date, no longer useful)
      Find:
      > Start at root:
      cd / && sudo find -name name_of_file
      > Start at directory dir:
      cd / && sudo find -name dir name_of_file

      .deb packages Installing .deb packages that are already downloaded to you:
      dpkg -i name_of_package.deb


      Searching for packages and version information

      > Run apt-get update, then:
      > Search: apt-cache searchname_of_package
      > find out which packages have new/newer versions (first install apt-show-versions):
      apt-show-versions -u
      > list of all packages, that contain or address "Kubuntu" is obtained by:
      apt-cache search kubuntu
      > for more information on a particular package, you can use:
      apt-cache show name-of-package
      > All installable versions of a package (they depend on your sources.list) can be listed by typing:
      apt-cache policy name-of-package


      - - - - - - - - - - - - - - - - - - - -
      Repair APT

      Close all windows that have anything to do with installing packages, close Muon, open your Konsole, and enter 3 commands:
      sudo dpkg --configure -a
      sudo apt-get update
      sudo apt-get -f install # This may be a “best” choice

      Two useful commands:
      dpkg –configure or dpkg –configure -a
      (configures unconfigured packages)
      dpkg-reconfigure or dpkg-reconfigure -a
      (reconfigure already configured packages)
      -a option: with the -a option, both commands will configure all packages that meet the criteria
      (NOTE: dpkg-reconfigure -a may take a while)

      Usual scenarios where you want to use them:
      dpkg --configure -a
      When upgrade has been interrupted by errors or crash, to complete the installation of packages
      dpkg-reconfigure package_name
      When you want to change the package behavior, it will ask debconf questions (again)
      so you can change your answers and modify the configuration


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

      End of Part 3

      REFERENCES

      Tuxfiles: http://www.tuxfiles.org/
      Psychocats: explains “Running sudo graphically” using kdesu/kdesudo;
      http://www.psychocats.net/ubuntu/graphicalsudo
      Nice links:
      https://help.ubuntu.com/community/CommandlineHowto
      https://help.ubuntu.com/community/Ad...mmandlineHowto
      Advanced, neat commands: Command Line Kung-Fu:
      http://www.commandlinefu.com/command.../sort-by-votes

      - - - - - - - - - - - - - - - - - - - -
      Addendum:

      A permissions calculator for the chmod command

      Permission calculator
      http://www.robolink.co.uk/calculators10.htm

      You don't really need this, of course, but it's sorta fun; and you can mess with it to see some common combinations. (Of course, if you use Firefox with NoScript, make sure NoScript is set to "temporarily allow" the site, so it can recalculate for you as you enter checkmarks in the boxes.)
      => Learning exercise: Use the tool to make your own table of permissions in OOo Writer.
      Last edited by Qqmike; Feb 24, 2015, 08:36 PM.
      An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

      Comment


        #4
        Re: Commands at Konsole: Beginners

        I would just like to say that I have read a few howtos about Linux commands, which are new to me - and I am not even really interested, but I realise I need them - and your introduction is definitely the most readable one I have found yet. I have saved this file and intend to learn from it! Thank you.

        Comment


          #5
          Re: Commands at Konsole: Beginners

          Thanks for your nice comment and your feedback.
          An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

          Comment


            #6
            Re: Commands at Konsole: Beginners

            Wow

            The first lesson has sorted out at last what three years of buggering about and tinkering have taught me but in one page!

            Many thanks

            Andy
            Running Kubuntu Karmic Koala&nbsp; with KDE 4.3 at home<br /><br />Kubuntu user 24342<br /><br />Running Dell Inspiron 530 Dual Core 3ghz<br /><br />and also running Kubuntu on a Lenovo thinkpad using a live pen drive<br /><br />Still no Microsoft here!

            Comment


              #7
              Re: Commands at Konsole: Beginners

              Here are a couple of links worth bookmarking, on the topic:

              http://wooledge.org:8000/BashFAQ

              http://wooledge.org:8000/BashGuide

              Comment


                #8
                Re: Commands at Konsole: Beginners

                andybleaden -- thanks for your nice comment! --Mike


                dibl -- good, thanks!



                At the risk of repeating myself or someone else, I'll tack this on here, also, and a loop back to yours::


                ********************

                More References:

                Bash Reference Manual
                http://www.gnu.org/software/bash/manual/bashref.html
                Also: See dibl's Reply above.

                File Management
                http://polishlinux.org/console/file-...ment-in-linux/
                An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

                Comment


                  #9
                  Re: Commands at Konsole: Beginners

                  no worries matey ...i have been tinkering too long ( or maybe not long enough!) I got the hand of sudo update etc recently and conky and other things..but not this

                  I also struggled for a while with downloading and installing software tar giz files but have found helpful guidance recently on other forums ...but in truth I am still not 100% but that will come with practice.

                  Used the facility to kick info via > to a txt file to print out my mp3 collection yesterday thanks to you so ta again
                  Running Kubuntu Karmic Koala&nbsp; with KDE 4.3 at home<br /><br />Kubuntu user 24342<br /><br />Running Dell Inspiron 530 Dual Core 3ghz<br /><br />and also running Kubuntu on a Lenovo thinkpad using a live pen drive<br /><br />Still no Microsoft here!

                  Comment


                    #10
                    Re: Commands at Konsole: Major Rewrite

                    Major re-write of the tutorial Command at Konsole

                    It is far better, more tutorial, covers basics to intermediate topics and a few advanced-intermediate topics. Expanded topic coverage. A complete tutorial for beginners and others. Some 10,000 words now, in three parts.

                    I need to check it over some more because there were some logistical problems getting it copied here and formatted, but I think it's in pretty good shape and that I tested all the examples.

                    Users/experts: Let me know of typos or errors of content.

                    Three parts:

                    Part 1: The original post
                    Part 2: Reply #1
                    Part 3: Reply #2


                    CONTENTS


                    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:
                    -- Create a text file
                    -- Create a directory
                    -- Command Summary table: mv, mkdir, cp, rm
                    -- Making folder backups with cp -r
                    -- 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
                    -- Command: history; Up & Down Arrow
                    -- Alias: make your own command alias name='command'
                    -- Checksums: md5sum filename

                    -- Wildcards: * ? [...] {...}
                    -- 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
                    -- Tar files: Viewing the contents
                    -- Chroot into a partition
                    -- Environment Variables printenv; echo $PATH
                    -- Example: Working at a prompt: a gparted screenshot
                    An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

                    Comment


                      #11
                      Re: Commands at Konsole: Beginners

                      Copying hidden folders ---

                      I just added a section in Part 2 about copying hidden folders and files.
                      This came from a tip provided to me by JohanLingen under Building a Live Kubuntu Flash Drive:

                      cp -RT dir1 DESTfolder
                      The result is the contents of dir1 copied into DESTfolder, including any hidden folder(s) (nested) and hidden files.

                      I'm not sure I've thought about this very much until JohanLingen pointed it out.

                      --Another correct way to do it, that I've seen is:
                      cp -r dir1/.[a-zA-Z0-9_]* DESTfolder
                      cp -r dir1/[a-zA-Z0-9_]* DESTfolder


                      However, this is incorrect:
                      cp -r dir1/* DESTfolder
                      This cp statement will NOT copy the hidden folders inside dir1.
                      It will copy a non-hidden folder and a hidden file in that folder, though (based on my experiments).

                      I also have wondered about the options
                      R (upper case versus the lower case -r -- what's the difference?)
                      T (upper case) --?

                      Thanks to JohanLingen.

                      Any other comments/discussion/tips would be of interest and welcome.


                      An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

                      Comment


                        #12
                        Re: Commands at Konsole: Beginners

                        Originally posted by Qqmike
                        cp -r dir1/* DESTfolder
                        This cp statement will NOT copy the hidden folders inside dir1.
                        This depends on how globbing (shell expansion) is set in your bash session, if dotglob option is not set, '*' does not include dotfiles or directories. if you set it with 'shopt -s dotglob', the command should work as you'd expect.

                        R (upper case versus the lower case -r -- what's the difference?)
                        There is none, -r, -R and --recursive behave exactly the same.

                        T (upper case) --?
                        http://www.gnu.org/software/coreutil...rget-directory

                        Comment


                          #13
                          Re: Commands at Konsole: Beginners

                          Many thanks for all that good information.

                          I tried the
                          shopt -s dotglob
                          and it worked as you said it should: cp -r copies everything now.

                          So, that has to be set in each BASH session, right?


                          And thanks for the other stuff
                          -r = -R
                          and the T reference.
                          An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

                          Comment


                            #14
                            Re: Commands at Konsole: Beginners

                            Originally posted by Qqmike
                            So, that has to be set in each BASH session, right?
                            If you prefer it, you can set the option in your ~/.bashrc
                            (and in case you need to unset it for some reason...'shopt -u dotglob')

                            Comment


                              #15
                              Re: Commands at Konsole: Beginners

                              Got it. Works perfectly.
                              Thanks, again.
                              An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

                              Comment

                              Working...
                              X