[go: up one dir, main page]

0% found this document useful (0 votes)
36 views7 pages

Linux

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 7

Admin commands

29 April 2023 20:58

1. Update software -> sudo apt-get update


2. sudo apt install build-essential dkms linux-headers-$(uname -r)
3. Putty
a. Clear -> clear the screen
b. Top -> cpu and ram consumption details
c. Df -> details about space and usage
d. Lsblk -> Disk partition details
e. sudo apt-get install -y bsdmainutils
4. Normal users => $ prompt
5. Super user / root / admin users => # prompt
6. / means root directory
7. In Linux everything is treated as a file
8. Linux files are divided into 3 types
a. Normal / ordinary files
b. Directory files
c. Device files
9. Know file type use file <name >
10. Ctrl +alt+t => to open terminal
11. Ctrl+d => to close the terminal
12. File types
First character represents the type of file
D -> directory file
- -> ordinary file
L -> link file
C -> character special file
B -> block special file
S -> socket file
13. Every directory contain two hidden files
a. . Current directory
b. .. Parent directory
14. Cd ~ go to user home directory
15. Cd - :
16. Bin contains binary executables related to commands used by normal user
Sbin contains binary executables related to commands used by super user

17. /etc/password -> contains all password information


18. /etc/group -> contains all group information
19. /etc/hosts -> contains all host information
20. -rwxrwxrwx 1 moksha moksha 39 Apr 30 07:58 cal_date.sh
- File type
- Rwxrwxrwx permissions
- Moksha : user / group name
- Moksha : group name
- 1 number of linked files
- 39 Apr 30 07:58 created / modified name
21. Ls -lt most recent at top and old files are later
22. Ls -ltr old filed should be at top and most recent should at last
23. Ls -tr
24. ls -altr
25. ls -A | wc -l : display number of files
26. Ls -F : to display all files by type
a. Directory /

Linux Page 1
a. Directory /
b. Executable file : *
c. Linked file : @
d. Ls -F /bin : example
27. ls -l /etc | head -20
28. ls -l -d */ -<
29. locate
Locate -n 5 *.conf -> it will display first 5 search results
Locate -I --limit 3 *.conf -> it will display in case sensitive and limit first 3 search results
locate -e *.json
locate --regex -i "(\.mp4|\.avi)"
Updatedb -> to update locate db

30 .vi
Command Insert Text
i before cursor
a after cursor
A at the end of the line
o open a line below the current line
O open a line above the current line
r replace the current character
R replace characters until <ESC>, overwrite

Cat /etc/passwd
Cat /etc/group
Cat /etc/hosts
$# number of arguments
$0 script name (./test.sh)
$1 first argument
$2 second argument
$* all arguments
$@ all arguments
$? Represents exit code of previously executed command or script

Scripts

#! /bin/bash
echo "The Number for arguments : $#"
echo "The Script Name : $0"
echo "The First argument " $1"
echo "All Arguments : $*"
echo "All Arguments with : $@"

Linux Page 2
$@ -> all commands line arguments with space separator
$* -> all commands line arguments with single string default is space

Find length of string

#! /bin/bash
len=$(echo -n "$1" |wc -c)
echo "The length of given string $1 : $len"

Date : date +%d_%B_%Y

• %D – Display date as mm/dd/yy


• %Y – Year (e.g., 2020)
• %m – Month (01-12)
• %B – Long month name (e.g., November)
• %b – Short month name (e.g., Nov)
• %d – Day of month (e.g., 01)
• %j – Day of year (001-366)
• %u – Day of week (1-7)
• %A – Full weekday name (e.g., Friday)
• %a – Short weekday name (e.g., Fri)
• %H – Hour (00-23)
• %I – Hour (01-12)
• %M – Minute (00-59)
• %S – Second (00-60)

Create time based folder and copy

#!bin/bash
timestamp=$(date +%d_%B_%Y)
echo $timestamp
rm -r $timestamp
mkdir $timestamp
cp *.sh $timestamp/

Remove blank lines in file


Linux Page 3
Remove blank lines in file

awk 'NF' file


grep -v -e '^$' abc.txt

Ls [!abc]* -> list all files not start abc


Ls [a-z] * -> list start all lower case
Ls [[:lower:]] *

Grep

==========

egrep 'Apple|Java' abc.txt


egrep -v 'Apple|Java' abc.txt
egrep -v '(Apple|Java)' abc.txt
egrep -i '(apple|Java)' abc.txt
grep -i '^the' abc1.txt -> print lines start with the word
egrep -i '(java|python)' abc1.txt

==========
uname
Uname -a display linux version
Uname -s
Uname -n node name
Uname -o operating system
Uname -r kernal name
Uname -v kernel version
Uname -m machine 64 or 32
Uname -p processor name
Uname -I hardware platform

Uptime

Uptime

Tmux
Linux Page 4
Tmux

tmux new -s Session1


tmux attach -t <name>

1. On the command prompt, type tmux new -s my_session,


2. Run the desired program.
3. Use the key sequence Ctrl-b + d to detach from the session.
4. Reattach to the Tmux session by typing tmux attach-session -t my_session.

Ctrl+b c Create a new window (with shell)


Ctrl+b w Choose window from a list
Ctrl+b 0 Switch to window 0 (by number )
Ctrl+b , Rename the current window
Ctrl+b % Split current pane horizontally into two panes
Ctrl+b " Split current pane vertically into two panes
Ctrl+b o Go to the next pane
Ctrl+b ; Toggle between the current and previous pane
Ctrl+b x Close the current pane

Linux Page 5
Linux Page 6
Login Credentials
04 May 2023 20:52

Moksha

Apple@4321

192.168.1.7

How to connect with Putty to Oracle VM VirtualBox Linux

Linux Page 7

You might also like