tony kombol
Download
Skip this Video
Download Presentation
Linux Command Basics II

Loading in 2 Seconds...

play fullscreen
1 / 38

Linux Command Basics II - PowerPoint PPT Presentation


  • 123 Views
  • Uploaded on

Tony Kombol. Linux Command Basics II. man review… . man on-line user manual man command_you_want_info_on type q to exit examples: for ls (list directory) man ls for cp (copy) man cp. su. Switch user. su. su userid su is short for s witch u ser

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Linux Command Basics II' - corby


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
man review
man review…
  • man
    • on-line user manual
    • man command_you_want_info_on
    • type q to exit
  • examples:
    • for ls (list directory)
      • man ls
    • for cp (copy)
      • man cp
slide3
su

Switch user

slide4
su
  • su userid
  • su is short for switch user
    • temporarily assume the id of another user
    • If no userid is supplied root is assumed
      • Hence the term superuser is sometimes assumed for su
    • Useful in cases when need to be the superuser for a small number of tasks
      • or any user!
slide5
su
  • It is often useful to become the superuser (root) to perform important system administration tasks
    • But as previously warned do not stay logged on as the superuser
  • Fortunately, there is a program to give temporary access to the superuser\'s privileges:
    • su userid
    • If userid not specified, root is assumed
slide6
su
  • To become the superuser or root
    • Debian:
      • Type the su command
    • CentOS:
      • Type the su – command
        • The – is important, in CentOS it gives the privilages
    • Then prompted for root\'s password:

[[email protected] me]$ su

Password:

[[email protected] me]#

  • After executing the su command, a new shell session as the superuser is started
  • To exit the superuser session
    • type exit
    • Returns to previous session (user)
file access
File Access

Permissions

what are permissions
What are Permissions?
  • The Unix operating system families are not only multitasking but are also a multi-user
  • What exactly does multi-user this mean?
    • More than one user can be operating the computer at the same time
    • While the computer might only have one keyboard and monitor, it can still be used by more than one user
      • If the computer has serial ports users may access the computer via them
      • If a computer is attached to a network, or the Internet, remote users can log in via telnet or ssh (secure shell) and operate the computer
what are permissions1
What are Permissions?
  • To make multiple access practical, a method had to be devised to protect the users from each other
    • Actions of one user should not crash the computer
    • One user should not be able interfere with the files belonging to another user
files permissions
Files Permissions
  • Unix and Linux use the same permissions scheme
    • Each file and directory is assigned access rights for:
      • Owner of the file
        • By default the userid that created the file
        • Can be re-assigned
      • Members of a group of related users
        • By default the owner
      • Everybody else (the world)
    • Rights can be assigned to:
      • read a file (look at it)
      • write a file (change it)
      • execute a file (run the file as a program).
files permissions1
Files Permissions
  • To see the permission settings for a file use the ls command with the –l option:

[[email protected] me]$ ls -l some_file

  • Typical response:

-rw-rw-r-- 1 me us 1097374 Sep 26 18:48 some_file

files permissions2
Files Permissions
  • By looking at the returned permissions-rw-rw-r-- 1 meus 1097374 Sep 26 18:48 some_file a lot can be determined from examining the results of this command:
    • It is a normal file
      • Signified by the “-” on the left
    • The file "some_file" is owned by user "me"
      • User "me" has the right to read and write this file
    • The file is owned by the group “us"
      • Members of the group “us" can also read and write this file
    • Everyone else can only read this file
files permissions3
Files Permissions
  • To interpret the first portion (10 characters) of the listing:
    • First character indicates the file type
      • -: normal file
      • d: directory
      • l: link
    • Followed by three sets of three characters
      • Owner
        • First three
      • Group
        • Second three
      • Everybody else (world)
        • Last three
    • Each set conveys permissions for
      • Reading
        • First character
      • Writing
        • Second character
      • Execution
        • Last character
permissions
Permissions
  • Change the file permissions (access):
    • chmod
      • modify file access rights
    • chown
      • change file ownership
    • chgrp
      • change a file\'s group ownership
chmod
chmod
  • Change the permissions of a file or directory
    • Specify the desired permission settings and the file or files to be modified
  • Two ways to specify the permissions
    • Octal
    • Symbolic
chmod octal
chmod (octal)
  • Permission settings can be thought of as a series of bits for each grouping
    • First bit for read
    • Second for write
    • Third for execute
  • Example:
    • rwx rwx rwx = 111 111 111
    • rw- rw- r-- = 110 110 100
    • rwx --- --- = 111 000 000
    • and so on...
    • Therefore for each group of 3 bits:
      • rwx = 111 in binary = 7
      • rw- = 110 in binary = 6
      • r-x = 101 in binary = 5
      • r-- = 100 in binary = 4
      • Etc.
    • Octal is perfect for noting permissions!
c hmod octal
chmod (octal)
  • By representing each of the three sets of permissions (owner, group, and other) as a single octal digit
    • Have a convenient way of expressing the permissions settings
  • Example: set some_file to have read and write permission for the owner, but keep the file private from others, enter the command:
directory permissions
Directory Permissions
  • chmod command can also be used to control the access permissions for directories
    • Permissions scheme for directories similar to files
      • R – view directory contents
      • W - create or delete files in the directory
      • X – Allow users to change into directory (cd dir)
c hmod symbolic mode
chmod (symbolic mode)
  • chmod [ugoa] [+-=] [rwx] fname
    • The first symbol is the reference (who) to change:
      • u: user (owner)
      • g: group
      • o: others (world)
      • a: all
      • Multiple references may be specified…
    • The second symbolis to add, remove or set a permission
      • +: add the permission
      • -: remove the permission
      • =: make it the exact permission
    • The last symbol is the permission to change
      • r: is to read
      • w: is to write
      • x: is to execute
      • Multiple permissions may be specified
c hmod symbolic mode1
chmod (symbolic mode)
  • Examples:
    • chmod u+w change.sh
      • Add the ability of the owner (user) to edit change.sh
        • Really to save it after it is changed
      • Does not change any other permissions
    • chmod a-x xyz.sh
      • Remove execute for everyone (all)
c hmod octal or symbolic
chmod: octal or symbolic?
  • Octal:
    • Can set all permissions with 3 characters
    • Easiest to change all permissions to an exact specification
  • Symbolic:
    • Can easily alter one permission for a reference
  • Know and use both effectively!
chown
chown
chown1
chown
  • Notice that in order to change the owner of a file, you must have root authority!
    • To do this, our example:
      • employed the sucommand for a root shell
      • executed chown
      • typed exit to return to our previous shell
  • chown works the same way on directories as it does on files
chgrp
chgrp
  • Change the group ownership of a file or directory
  • Command format:
  • In the example above
    • Group ownership of some_file changed from its previous group to "new_group"
  • Must be the owner of the file or directory to perform a chgrp
job control1
Job Control
  • Several commands available to control processes
  • The most commonly used:
    • kill
      • sends a signal to one or more processes
      • usually to "kill" a process
slide29
kill
  • Suppose a program becomes unresponsive
  • How to get rid of it?
    • Use the kill command
    • Let\'s try this out on xload:
      • First, identify the process to kill
        • Use either jobs or ps to do this
      • jobs will return a job number
      • ps returns a process id (PID).
slide30

Start xload and return control to terminal

Use jobs to see who is running  [1] is the id number

Kill id 1

Start xload again

Use p to see the procsss status  1293 is xloads process id

Kill process1293

[[email protected] me]$ xload &[1] 1292

[[email protected] me]$ jobs[1]+ Running xload &

[[email protected] me]$ kill %1

[[email protected] me]$ xload &[2] 1293[1] Terminated xload

[[email protected] me]$ psPID TTY TIME CMD1280 pts/5 00:00:00 bash1293 pts/5 00:00:00 xload1294 pts/5 00:00:00 ps

[[email protected] me]$ kill 1293[2]+ Terminated xload

slide32
grep
  • Flexible and powerful text search utility
  • Basic syntax:
    • grep search-item file.searched
  • Can get very sophisticated
    • http://unixhelp.ed.ac.uk/CGI/man-cgi?grep
    • can use regular expressions
    • can search multiple files
pipes
Pipes
  • “|”
    • Takes the output of one program and uses it as input to another
    • E.g.:
      • du | less
redirection
Redirection
  • “>”
    • Take the output and (re)place in a file
      • Create the file if it does not exist
      • Replace the file if it does exist
    • “>>”
      • Appends data to existing file
  • “<“
    • Take the input from a new source (file)
reminder autocomplete and recall
Reminder: Autocomplete and Recall
  • Autocomplete
    • Tab key
      • Start the command or name
      • Hit Tab
      • If what you typed is unique up to that point bash will complete the rest of the typing!
      • If what you typed is not unique it will give a gentle beep
        • Hit Tab again to get a list of matches
  • Recall
    • The up arrow will recall previous commands
    • The down arrow recalls later commands
your own top 10 linux commands
Your own top 10 Linux commands
  • When commands are entered on the terminal they are kept in the history library
  • List your top 10 by with the history command:
    • History by itself gives the last ~500 commands
    • Use pipes and filters to get the reduced data

history | awk \'{print $2}\' | awk \'BEGIN {FS="|"}{print $1}\' | sort | uniq -c | sort -n | tail | sort -nr

ad