Top 10 sys­tem tips

Make good use of the Ter­mi­nal with this col­lec­tion of com­mands.

Linux Format - - ESCAPE WINDOWS -

From us­ing the Ter­mi­nal to ex­plore the filesys­tem, to find­ing out more about the sta­tus of your hard­ware, be­com­ing fa­mil­iar with th­ese com­mands is a must.

1 Get help

There are three ways to get help in the Ter­mi­nal: Know the name of the tool? Use the --help flag: $ ls --help

The whatis tool is another use­ful help-re­lated com­mand, pro­vid­ing you with a brief de­scrip­tion of a fully formed com­mand: $ whatis apt-get in­stall vlc

This will de­scribe the apt-get tool, the in­stall ar­gu­ment and what pack­age vlc is. Note, how­ever, that whatis ig­nores any flags.

Fi­nally, the Ter­mi­nal also pro­vides ac­cess to a full-blown online man­ual via the man util­ity. Start with man in­tro for a long and de­tailed in­tro­duc­tion of the Ter­mi­nal it­self, and man man for ad­vice on nav­i­gat­ing the man­ual. Fi­nally, pair it with a spe­cific tool – for ex­am­ple, man apt-get – for a de­tailed de­scrip­tion of that tool writ­ten by pro­gram­mers.

2 Nav­i­gat­ing the filesys­tem

Open the Ter­mi­nal and you start within your home folder. Use the ls -l com­mand to con­firm this. If you’d like to view all hidden files and fold­ers (ba­si­cally file­names with a full stop at the be­gin­ning – such as .hidden.sh), use ls -a . You can also view the con­tents of sub-fold­ers within the cur­rent folder too, us­ing ls --re­cur­sive .

The cd com­mand en­ables you to quickly move be­tween direc­to­ries. To move inside a sub-folder within the cur­rent folder, use cd <Dir­name> (re­mem­ber, fold­ers and files are case sen­si­tive with Linux). To go back up a level, use cd .. or cd ../.. to jump up two lev­els. To nav­i­gate to the root di­rec­tory, use cd / or type cd ~ to go to your /Home di­rec­tory.

Type cd /path/to/folder to jump di­rectly to another folder us­ing its ex­act path (or cd ~/Doc­u­ments if it’s inside your Home folder). Fi­nally, type cd - to go back to the pre­vi­ous di­rec­tory you were in. If your folder path con­tains spa­ces – for ex­am­ple, a folder named Star Trek, then you need to en­com­pass the en­tire path inside sin­gle quo­ta­tion marks: $ cd ‘~\Videos\Star Trek’ Hand­ily you can tap the tab key to auto-com­plete file names.

3 Copy, move and delete

Need to ma­nip­u­late files within the Ter­mi­nal? Start by fa­mil­iaris­ing your­self with the cp (copy) and mv (move) tools, which share the same syn­tax: $ cp -i source des­ti­na­tion Both source and des­ti­na­tion can be com­plete folder paths, or just use the file­name if you’ve al­ready nav­i­gated to the folder con­tain­ing the orig­i­nal file, while the -i flag en­sures you’ll re­ceive a warn­ing if you try to over­write an ex­ist­ing file of the same name. For ex­am­ple: $ cp -i in­voice.odt ~/Doc­u­ments/Backup

If you want to re­name the copied file, sim­ply ap­pend it to the end of the des­ti­na­tion: ~/Doc­u­ments/Backup/in­voice­backup.odt for ex­am­ple. Sim­i­larly, cp in­voice.odt in­voice­backup.odt will cre­ate a re­named du­pli­cate of the file in the same folder. Sub­sti­tute mv to move or re­name a file. If you want to copy a folder, use the -r flag to show re­cur­sion, which means the folder and its con­tents will be copied or moved.

Delete in­di­vid­ual files us­ing rm , and empty fold­ers can be re­moved with the rmdir com­mand (add the -r flag to delete a folder and any ex­ist­ing con­tents):

$ rmdir -r ~/Doc­u­ments/Backup Fi­nally, cre­ate new fold­ers us­ing the mkdir fold­er­name com­mand (again full paths are sup­ported), and use touch file­name to cre­ate a new, empty file – for ex­am­ple, touch con­fig.sys . When cre­at­ing fold­ers with spa­ces in the name, re­mem­ber to sur­round them with sin­gle quo­ta­tion marks or by us­ing a back­slash (called an es­cape) char­ac­ter (\) be­fore the trou­ble­some space, for ex­am­ple: ‘mkdir Star\ Trek’ .

4 Change per­mis­sions

Nau­tilus pro­vides some tools for tweak­ing per­mis­sions, but it’s quicker to use the chmod tool us­ing the fol­low­ing syn­tax: $ chmod 777 file The file is ob­vi­ously the name of the file, and can also re­fer to a folder (if you want to set all the folder’s con­tents – in­clud­ing sub-direc­to­ries – to the same per­mis­sions as the folder it­self, add the -R flag like so: $ chmod -R 777 folder

The key el­e­ment here is the num­ber 777 (never use this for sys­tem files), which refers to the per­mis­sions you’re set­ting. 7 stands for rwx (so full ac­cess), and the first num­ber refers to the file owner, the sec­ond to the file’s group and the third to ‘every­one else’, as out­lined ear­lier in this fea­ture.

Other num­bers worth con­sid­er­ing are 6 ( rw- , or read/ write but no ex­e­cute), 5 ( r-x, or read and ex­e­cute), and 4 ( r-- , or read-only). So, as­sign 644 to a folder or file and you’re giv­ing the owner read and write ac­cess, but re­strict­ing all oth­ers to read-only ac­cess. Set 775 and you’re giv­ing the owner and named group full ac­cess, while every­one else can read and ex­e­cute the file. Be­fore div­ing into per­mis­sions, read https://help.ubuntu.com/com­mu­nity/FilePer­mis­sions.

5 Change user and owner

If you want to change the owner or group of a se­lected file or folder, use the chown com­mand. $ chown user file You can use chgrp to change the group of a file, us­ing the same syn­tax ( chgrp group file ), or you can use chown to change both user and group with one com­mand, like so: $ chown owner:group file

6 Run multiple com­mands to­gether

There are three ways to run two or more com­mands to­gether on a sin­gle line (en­abling you to wan­der off and make a cuppa while your PC gets on with the job). If you only want the sec­ond com­mand to run if the first com­pletes suc­cess­fully then use the && ar­gu­ment, like so: $ sudo apt-get up­date && sudo apt-get up­grade

If you wanted the sec­ond com­mand to run only if the first com­mand failed, then sub­sti­tute || for &&. Fi­nally, use a semi­colon (;) to run the sec­ond com­mand re­gard­less of what hap­pens with the first: $ sudo apt-get up­date ; sudo apt-get re­move vlc

7 Edit­ing with nano

One pop­u­lar use for the Ter­mi­nal is to edit con­fig­u­ra­tion files. The best tool for the job is nano , which works just like a reg­u­lar text edi­tor. In­voke it thus: $ sudo nano /path/file­name You’ll no­tice the Ter­mi­nal change to the nano in­ter­face – the file­name and path is listed at the top, and a list of ba­sic com­mands are shown at the bot­tom – the ^ sym­bol refers to the [Ctrl] key.

Your file’s con­tents take up the main area of the nano in­ter­face – there’s no text wrap­ping, so look for $ sym­bols on the right in­di­cat­ing the line doesn’t fit (re­size the win­dow or press [End] to jump to the end of the line).

Use [Home]/[End] to jump to the start and end of a line, or [PgUp]/[PgDn] to move pages at a time. Press [Alt] + [/] to go to the bot­tom of the doc­u­ment, and [Alt] + [\] to jump back to the top. Use [Ctrl] + [W] to search your file, press­ing [Alt] + [W] to look for ad­di­tional matches.

8 Write to a USB drive

What if you need to cre­ate a bootable USB drive from an ISO file you’ve down­loaded? The dd tool leaps to the res­cue, but we’d ad­vise us­ing it with care – the fol­low­ing com­mand wipes the tar­get drive as part of the copy oper­a­tion, so be sure you’ve iden­ti­fied the correct drive be­fore you be­gin us­ing sudo fdisk -l : $ sudo dd if=file­name.iso of=/dev/usb sta­tus=progress

As you’d ex­pect, sub­sti­tute /dev/usb with the correct drive iden­ti­fier (such as /dev/sdc ).

The Ter­mi­nal comes with lots of help and doc­u­men­ta­tion for you to plun­der as re­quired.

Be care­ful cre­at­ing fold­ers with spa­ces in the ti­tle – we show you how to do it cor­rectly

Newspapers in English

Newspapers from Australia

© PressReader. All rights reserved.