linux commands |
well here i will give you some useful common linux commands
- WHY?
well if you are using linux without GUI 'Graphic user interface' you just can do nothing without them! you need them to give linux the commands and tell it what you want to do.and you need to know all the commands to work on it!
and if you are using a linux OS with GUI like ubuntu
you also need it because some times you could find some errors or you need to do things faster and they are perfect for that.
and for sure i will give some examples for them .
- WHERE?
well you will use linux commands in the command line or 'terminal'.
- the commands :
first the comment :
any line start with '#' it is a comment and it is ignored by the system.
Example:
#i am a comment am ignored.
echo "#i am not a comment! am a string!"
then those variables meaning:
$USER = the computer user.$HOSTNAME = the computer name.
i will explain them later in the echo command. keep reading...
well i will start with the most easy and important .
most of the command syntax are like this:
command [option] <argument>command = command name (cd,ls,echo...)
option = option defined for each command mostly is a letter after a dash (-i,-f...)
argument = the argument or value of the command to give such as if it was copy the argument is the file.
always to know the command options type:
command --helpand you will get anything about the command .
or for more info type :
info command
type:
helpfor bash commands help
- the commands:
1-
pwdthe command 'pwd' show you in witch directory you are working in.
hmmm well everyone know what that means but if you asked anyway whats that means?
in DOS in windows if you opened the cmd 'command line' you will find something like this:
C:\WINDOWS\system32>or sometimes:
C:\WINDOWS\Document and settings>
P.S: you can see that linux uses slash sign '/' in the path view else Windows uses the backslash sign '\'.
anyway, this "C:\WINDOWS\system32" means that you are in the system32 folder ! that mean if you created a folder it will be created inside the system32 folder.
the same thing for linux!.
2-
cdthe command 'cd' means 'Change Directory' it is simple ! it used to change the directory you are working in!
Example :
you are in the home directory.
you will see this
user@computername:~$
ok now you want to go to the 'etc' folder you will type:
cd /etc/
now you will get this
user@computername:/etc$
thats mean you are now in the 'etc' directory!
now you want to go to a folder called 'test' in the home directory.
type:
cd /home/$USER/test/
you will get
user@computername:/test$
that's mean you are in the 'test' directory now!
to get back to your home directory anywhere anytime just type:
cd
and you will get back to it!.
3-
echoecho used to write or 'print' in linux bash commands.
Example :
type in the command line :
echo 'mk & mt'
you will get :
mk & mtit is so simple! it is also used to know the variables .
Example :
$USER defined the computer user and $HOSTNAME defined the computer name. type :
echo $USER
and you will get whats your user account name on the computer.
type :
echo $HOSTNAME
and you will get the computer name.
also echo used to write into files!
Example: you will make a text file called 'commands' and you will write the commands in it.
first make sure that you are at home directory by typing:
cd
then type
echo 'pwd show witch directory you are in , cd to change directory ,echo to write "print" or to know variables or to write into files!! '> commands.txt
now check your home directory and check the 'commands.txt' file.
4-
lswell the 'ls' command usually used at linux without GUI !
it used to know what the directory what you are in have such as files or folder.
Example:
you are at the home directory and you want know what it have just type :
ls
and you will get a list of the folders and files that the home directory include .
also if you are at the home directory but you want to know what the 'test' folder include just type:
ls /home/$USER/test/
and you will get a list of what the test folder have.
P.S: in ubuntu 'i don't know about others OS' you can use the '~' sign instead of '/home/$USER/' thats mean in the last Example it can be like this:
ls ~/test/
5-
su
in linux DO NOT BE AN ADMIN OF THE COMPUTER!
or else your computer will be worse than other one with Windows on it.
why?
the security thing in ubuntu that every time anywhere you want to adjust something belong to system you will be asked to type the admin password .so if you where an admin you won't be asked so your system would be vulnerable to be corrupted.
so if you are not the admin and you need to adjust something in the system 'like editing the hosts file , installing packages , changing connection settings' or doing anything else not in the home directory you need to permission to do it.
for ubuntu 'or any other with GUI' you will asked to type the password through a window .
but sometimes you need to permission while you are working on the command line so you will need the command 'su' it give you TEMPORARY admin permission.
Example:
you want to create a folder into the 'bin' directory you simply type first:
#go to bin directory by cd
cd /bin/
#take the admin permission
su
#you will be asked for the admin password
#then to make a directory with mkdir
mkdir test-in-bin
#to check that the folder has been created type ls to see the folder #inside the bin
ls
or if you want the admin permission for one command use the 'sudo'.
Example:
sudo mkdir /bin/test-in-bin
so it will be done.
5-
mkdirused to create folders as shown in the Example above
6-
cpcp used to copy files and folders.
Example:
you have a 'test.txt' file in your home directory and you want to copy it to 'test' directory type:
#be at home
cd
#start coping
cp test.txt ~/test/
#check if it has been copied with ls
ls ~/test/
to copy directory use 'cp' with the option [-R] .
to force copy sued 'cp' with the option [-f].
for more option use 'cp --help'.
7-
dkpg -iused in ubuntu to install all packages '.deb files' .
Example:
you have packages in your home directory you want to install it type:
#be at home
cd
#installing packages need admin permission so we will use sudo
sudo dkpg -i *.deb
P.S: *.deb refer to all files with .deb extension .
8-
chmodchmod used to change files permissions for users or groups.
Let’s take a closer look at the contents of a sample directory by typing the command
ls -l
'the “l
” stands for
“long”.'
you will get something like this:
total 42 6 5 4 3 2 1 | |||||
-rwxr-xr-x -rw-rw-r-- -rw-rw-r-- -rw-r--r-- drwxrwxr-x -rw-r----- -rwxr-xr-x |
1 1 1 1 2 1 1 |
joe acctg joe acctg joe acctg joe acctg joe acctg joe acctg joe acctg |
23068 12878 2645 168 1024 512 2645 |
Feb 26 2004 Jul 24 21:58 Jun 30 08:48 Jul 17 11:51 Mar 18 16:27 Sep 1 07:00 Aug 4 11:03 |
archive.sh orgchart.gif personnel.txt publicity.html sales topsecret.inf wordmatic |
as you can see this is a table of the files in the directory that you've chosen.
the 1 refer to names
the 2 refer to the date and time at which the file was last modified
the 3 refer to The size of the file, in bytes.
the 4 refer to the name of the owner of the file and the group to which the owner belongs.
the 5 refer to This column tells how many hard links there are for this file
the 6 The first character in this column tells what kind of file this is. The dash represents a normal file; the d represents a directory.
The remaining characters describe the file’s permission:
the first set three letters after the file type tell what you, the owner of the file, have permission to do.
an r in the first position means you are permitted to read the file. A w in the second position means you may write the file. This includes the ability to delete a file. An x in the third position means you may execute the file.
a dash in any position means that you don’t have that particular permission.
you must use chmod with options to defined what are the permissions and for who you are changing them.
syntax :
chmode {u|g|o|a}[+-]{r|w|x} filep.s: the '|' sign refer to 'or'.
- the first option you select for who you are changing the permissions:
u = user 'you the owner of the file'
g = groups
o = other users
a = all users
- the second option you select to give permission or deny permission:
+ = give
- = deny
- the third option you select the permission:
r = read
w = write
x = execute
Example:
the file test.txt :
-rwxr--r--that mean
from the first dash it means it is not a directory
the first rwx is for the owner and it means he can Read,Write and eXecute the file.
the second r-- is for the groups and it means they only can Read the file.
the third r-- is for other users and it means they only can Read the file.
now you want to change the file permission to make the all users to write on it 'also delete it'.
type:
chmod a+w test.txtso now the test.txt permissions will be:
-rwxrw-rw-now you want to deny the other people of write on the file 'or delete it'.
type:
chmod o-w test.txtso now the test.txt permissions will be :
-rwx-rw-r--
now those are the most important linux bash commands if you want to know more you can surf the net or visit http://linuxcommand.org/ to learn them all.
here is a pic of common bash commands:
double click to view in full size.
shell bash commands |
now the last thing.
how could i make bash .sh files 'like .bat patch files in windows' to run them .
easily open a text editor
type the following
#! usr/bin/shto defined that this is a bash script.
then open it .
most OS will open it but if it asked you how to open it use the command
sh
memo
0 comments:
Post a Comment
gotta some thing to say ?
Note: Only a member of this blog may post a comment.