Basic Linux Commands

From media_wiki
Revision as of 20:57, 7 September 2019 by U731219879 rc (talk | contribs) (Created page with " '''Basic System Commands''' '''pwd''' Absolute Path '''mkdir''' Make directory '''rmdir''' Remove directory '''rm''' Delete file '''cp''' Copy file '...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Basic System Commands

pwd  		Absolute Path
mkdir 	 	Make directory 
rmdir 	 	Remove directory
rm  		Delete file
cp 		Copy file 

touch - Create file.

  touch new.txt - Creates new.txt file with no data

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