Basic Linux Shell Commands - 2
Commands required to use UNIX-based operating systems effectively
We continue to examine the commands needed to use UNIX-based operating systems effectively. In the previous post, we looked at the most essential file system navigation commands. We also looked at basic vim commands.
In this post, I will be showing a few more commands for file manipulation.
The commands listed below will be described with example usages:
mv
Used to change the name or location of a file:
$ ls
newFile
$ mv newFile newFileRenamed
$ ls
newFileRenamed
$
cp
Used to copy a file from one place to another:
$ ls
newFileRenamed
$ cp newFileRenamed copyOfFile
$ ls
copyOfFile newFileRenamed
$
rm
The file delete command:
$ ls
copyOfFile newFileRenamed
$ rm newFileRenamed
$ ls
copyOfFile
$
mkdir
Creates a new directory (Make Directory)
$ ls
copyOfFile
$ mkdir newFileDir
$ ls
copyOfFile newFileDir
$
When we want to delete the newly created directory, we learn a new information about the rm command:
$ ls
copyOfFile newFileDir
$ rm copyOfFile
$ ls
newFileDir
$ rm newFileDir
rm: cannot remove `newFileDir': Is a directory
$
The rm command is sufficient to delete a file. For deleting a directory however, rm -rf command is used. (f: force r: recursive)
$ ls
newFileDir
$ rm -rf newFileDir
$ ls
$
zip
Used to compress files in .zip format:
$ ls
$ touch a #dosya yaratır
$ ls
a
$ zip a.zip a
adding: a (stored 0%)
$ ls
a a.zip
$
unzip
Used to open zipped files:
$ ls
a a.zip
$ rm a
$ ls
a.zip
$ unzip a.zip
Archive: a.zip
extracting: a
$ ls
a a.zip
$
tar
It is used to open compressed files in .tgz and tar.gz format which are more common on Linux platforms.
To compress an existing open (uncompressed) file, use the tar command with the -zcvf argument:
$ ls
a a.zip
$ tar -zcvf a.tar.gz a
a
$ ls
a a.tar.gz a.zip
$
Use the -xzvf argument to open an existing compressed file:
$ ls
a a.tar.gz a.zip
$ rm a
$ ls
a.tar.gz a.zip
$ tar -xzvf a.tar.gz
a
$ ls
a a.tar.gz a.zip
$
wget
Downloads the file at the given Web address:
$ wget http://download.thinkbroadband.com/5MB.zip
exit
If it is a session connected via SSH, it breaks the connection. If there is no SSH connection, the terminal closes:
$ exit
Connection to dev.lucidcode.com.tr closed.
Omers-iMac:~ omerg$
aptitude / apt-get
apt-get is a package manager for Debian Linux distributions. It allows you to find and install new applications.
For example, lets go to app repository and search for apps whose name includes ‘text’ within their name:
$ aptitude search text
p alsaplayer-text - PCM player designed for ALSA (text version
p bible-kjv-text - King James Version of the Bible - text and
p cl-contextl - context orientation for Common Lisp
p context - powerful TeX format
p context-modules - additional ConTeXt modules
p contextfree - image generator based on context-free gram
p dav-text - A minimalist ncurses-based text editor
p doc-linux-fr-text - Linux docs in French: HOWTOs, MetaFAQs in
p doc-linux-ja-text - Linux HOWTOs and FAQs in Japanese (TEXT fo
p docbook-xsl-doc-text - stylesheets
We will see a message when we want to download ‘dev-text’ application:
$ apt-get install dev-text
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
$
The apt-get install command requires Super User authorization because it is a command that makes modifications on the system. To run any command on Linux platforms with ‘sudoers’ authority, the ‘sudo’ suffix is added:
$ sudo apt-get install dev-text
To trigger a command by using the sudo attachment, the user must have ‘sudoers’ privilege. The admin user gives the privilege.
The apt-get install command is run again with the sudo attachment:
$ apt-get install dev-text
[sudo] password for omerg:
Congratulations! Now you are familiar with the most commonly used Linux Shell Commands.