Difference between revisions of "Basic Linux Commands"

From media_wiki
Jump to: navigation, search
Line 6: Line 6:
 
'''CD''' - Change Directory
 
'''CD''' - Change Directory
 
   '''cd Documents''' - Change to Documents Directory
 
   '''cd Documents''' - Change to Documents Directory
   '''cd Home/pi''' - Change to pi Directory
+
   '''cd home/pi''' - Change to pi Directory
 
   '''cd ..''' -  Return one level up  
 
   '''cd ..''' -  Return one level up  
   '''cd /''' - root Directory  
+
   '''cd /''' - Change to root Directory  
 
'''pwd''' - Print Working Directory Absolute Path
 
'''pwd''' - Print Working Directory Absolute Path
  
Line 24: Line 24:
 
   '''touch new.txt''' - Creates new.txt file with no data
 
   '''touch new.txt''' - Creates new.txt file with no data
 
   '''touch Documents/rusty.sh''' - Creates a empty file named '''rusty.sh''' in the folder '''Documents'''.
 
   '''touch Documents/rusty.sh''' - Creates a empty file named '''rusty.sh''' in the folder '''Documents'''.
 +
'''ls''' - Lists the content of the current directory
 +
  '''ls -l'''  - Display additional information (permissions, owner, group, size, date and timestamp of last edit)
 +
  '''ls -al'''  -  Allows you to view files beginning with a dot (.).
 +
 
'''echo''' -  Display text on Screen or Move text to file.   
 
'''echo''' -  Display text on Screen or Move text to file.   
 
   '''echo "Hello World"'''
 
   '''echo "Hello World"'''
Line 89: Line 93:
 
   '''last – i'''  - display IP numbers in numbers-and-dots notation
 
   '''last – i'''  - display IP numbers in numbers-and-dots notation
 
'''users''' user that are loged in
 
'''users''' user that are loged in
 +
 
'''who''' - who is loged in and when  
 
'''who''' - who is loged in and when  
 
   '''who -a''' All options
 
   '''who -a''' All options

Revision as of 22:10, 7 September 2019


Basic File System Commands

CD - Change Directory

 cd Documents - Change to Documents Directory
 cd home/pi - Change to pi Directory
 cd .. -  Return one level up 
 cd / - Change to root Directory 

pwd - Print Working Directory Absolute Path

mkdir - Make directory

 mkdir rusty - Creates a directory named rusty
 mkdir Documents/rusty - Creates a directory named rusty in the folder Documents. 

rmdir - Remove directory

 rmdir rusty - Deletes a directory name rusty
 rmdir Documents/rusty - Deletes a directory named rusty in the folder Documents. 

rm Delete file

 rm rusty.sh - Deletes a file named rusty.sh
 rm Documents/rusty.sh - Deletes a file named rusty.sh in the folder Documents.

cp Copy file touch - Create file.

 touch new.txt - Creates new.txt file with no data
 touch Documents/rusty.sh - Creates a empty file named rusty.sh in the folder Documents.

ls - Lists the content of the current directory

 ls -l  - Display additional information (permissions, owner, group, size, date and timestamp of last edit) 
 ls -al  -  Allows you to view files beginning with a dot (.).

echo - Display text on Screen or Move text to file.

 echo "Hello World"
 echo my name is Rusty >> new.txt 

cat - Display content of file.

 cat new.txt

chmod - To make a file executable.

 chmod 777 rusty.sh Executable and Readable. 

history - Linux store any command you type in an archive file.

 history -c - clear all the history
 history -r  - Read in the contents of the file
 history -w - Overwrites the history file 
 history -d123  - Delete line 123
 HISTCONTROL=erasedups 

head - Displays the beginning of a file

 head -n 5 filename.txt Display the first 5 lines of file
 head -c 5 filename.txt Specify the number of bytes.

tail - Displays the end of a file.

 tail -n 10 filename.txt  Display the last 10 lines of file

alias - This command creates an alias

 alias cls='clear'- Alias to clear screen
 alias ll='ls -al'- Alias 'ls' to change the default action of ls
 alias rm='rm -i' - Alias to prevent accidental deletion

aspell - Command line Spell checker

 aspell check sample.txt
Write to a file and append to it each time
 example: Ls -al >> filename.txt 
Write to a file and write over any previous data
 example: Ls -al > filename.txt

User Commands and user information

Add User Create a new user using useradd or adduser:

 sudo useradd -m (username) = user
 sudo useradd -m (username) -G sudo = administrator
 sudo adduser username

Users add Groups

 sudo adduser username dialout
 sudo adduser username sudo
 sudo adduser username adm
 Groups for pi - pi adm dialout cdrom sudo audio video plugdev games users input netdev spi i2c gpio lpadmin
 groups pi	Show groups for user pi
 groups rusty	Show groups for user rusty 

Remove Groups

 sudo deluser rusty adm -  Removes rusty from adm group.	

Remove User Delete a user

 sudo userdel rusty      - Delete user rusty
 sudo rm -rf /home/rusty - Remove the home directory of the user
 sudo userdel -r rusty  -  Delete user rusty and home folder.
 tail -1 /etc/passwd - Verify user

passwd Create/Change a user password

 sudo passwd (username)
 sudo passwd rusty		
 (Enter current) UNIX password
 Enter new UNIX password
 Retype new UNIX password

switch user

 sudo /bin/su - root
 su - Changes user to root user (password needed for root)
 su rusty - Changes user to rusty (password needed for rusty)

last - Show a listing of last logged in users.

 last -a - display hostnames in the last column
 last – F -  print full login and logout times
 last – i  - display IP numbers in numbers-and-dots notation

users user that are loged in

who - who is loged in and when

 who -a All options
 who -b Last boot
 who -m From where they are loged in
 who -q All users #users
 who -r Runlevel
 who --version Output version

whoami- print effective userid