Download presentation
Presentation is loading. Please wait.
1
Chapter 12 Command-Line Master Class
Ubuntu Unleashed Chapter 12 Command-Line Master Class
2
Redirect Output Redirection – changes the standard input/output for commands Standard input – keyboard Standard output – monitor To redirect output command line uses > cat myfile.txt > mynewfile.txt A new way to copy, but it will not warn you if you're about to overwrite a file Can also cat 2 (or more) files into a new file or add 1 file to the end of another cat file1 file2 > file3 Cat file1 >> file2
3
Redirect Input Useful if you don't want to enter several lines of info with a command I'll use the books example – making sure the same software is on 2 (or more ) PCs First we redirect output to put a program list into a file – sudo dpkg --get selections > pkg.list Now transfer this file to another PC and use the file as input – sudo dpkg --set selections < pkg.list To finish – sudo apt-get -u dselect-upgrade
4
stdin – stdout - stderr Automatic (implied) input/output By default:
stdin – keyboard – assigned number 0 stdout – monitor – assigned number 1 stderr – monitor – assigned number 2 If you wanted to redirect error messages to a file that you could view at your leisure program_name 2> error.log
5
Comparing files Finding differences – diff command
diff myfile.txt myfile2.txt Will display any non-identical lines from the two files Good for comparing current files with backups Finding similarities – comm command Comm myfile.txt myfile2.txt Will display a large amount of info in 3 columns column 1 – shows lines only in file 1 column 2 – shows lines only in file 2 column 3 – shows lines that are in both files
6
Combining commands Pipeline ( | )
Using a pipe between commands will turn the first commands output into the second commands input cat myfile.txt myfile2.txt myfile3.txt | less Would open 3 files on screen, but with the ability to scroll Semicolon ( ; ) Runs the commands in order without input/output switching ls;date;cat myfile.txt
7
Background/Boolean Use an Ampersand ( & ) to run tasks in the background Background tasks run without user input You'll be given a PID command_name & Boolean Operators && and || (double-pipe) Separate 2 commands with... && to only run the second command if the first works command1 && command2 || to only run second command if the first fails command1 || command2
8
Environmental Variables
Variables loaded at login – think “settings” in Windows (and beyond) Short list... PWD – provides the path to your working directory USER – will show current user LANG – sets default language SHELL – name and location of current shell PATH – sets default locations of executable files TERM – sets the type of terminal in use
9
Environmental Variables
To see the current value of any environmental variable, use echo $ echo $USER should display linuxes To display all environmental variables env command or printenv command echo $PATH will show where Linux will look for executables
10
Text Editors Several to choose from Console based
emacs – GNU editing environment nano – simple text editor vim – updated version of “vi” GUI based gedit – GUI text editor – installed with Ubuntu kate – a simple KDE based text editor Kedit – another simple KDE editor
11
nano Create a new file nano newfilename.txt Edit an existing file
nano filename.txt Simple commands initiated with the Ctrl key listed at bottom of screen One of the easiest non_GUI text editors
12
vim Almost universally available in Linux/Unix
Very capable but confusingly cryptic Press i to insert text Press Esc key to exit insert mode Press : (colon) to enter a command Commands include (by no means a complete list) x – deletes a character dd – deletes a line q – quits out of the program w – saves the file Run vimtutor for a 30 minute tutorial on vim
13
emacs Richard Stallman's editor (remember him?)
Editing environment – capable of more than editing – can create appointment book, calander, diary, etc Most commands require Ctrl key Ctrl + D – delete character Ctrl + A – go to start of line Ctrl + E – go to end of line And many many many more
14
Compressed Files bunzip2 and gunzip – uncompress files
bzip2 and gzip – compress files Tar – compress, uncompress and list To create a compressed file from a directory tar czf compressed_filename.tgz directoryname c compresses the file z creates gzip archive f filename t lists archive contents To expand tar zxf compressed_filename x expands archive
15
byobu Open multiple consoles from one console
Useful when using a machine remotely Instead of creating another ssh connection to open another console Type byobu and hit enter – a second screen opens replacing first one F2 – opens a new console F3 – goes back to previous console F4 – goes to next console F6 - disconnect F9 – opens help and config menu F12 – locks screen byobu creates a session that you can reconnect to and continue where you left off
16
Polite System Reset Shutting down by holding the power button can be harmful to your operating system Just sayin' Any computer can (and will) freeze up Shut your system down “politely” Hold down SysRq + Alt keys and press R – unRaw – takes keyboard control E – tErminate – sends SIGTERM to all processes I – kIll – sends SIGKILL to all remaining S – Sync – flush data from memory to disc U – Unmount – unmount all filesystems and remount as read only B – reBoot – restarts the computer Wait a few seconds between each keystroke
17
DOL and CCBY
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.