Directories

Each directory contains files with similar content. The typical directories that are found in Linux distributions are as follows:

/bin: Pronounced “bin,” this directory is where most of the binary files are stored. Inside it, you typically find the Linux terminal commands such as cd (change directory), pwd (print working directory), and mv (move).

/boot: Contains the files necessary for Linux to boot.

/dev: Here you find your mounted physical devices such as your hard drives, USB drives, and optical drives.

/etc: This directory is where the configuration files of the installed software are located.

/home: The home directory contains a directory for each user with the user’s files and directories. The figure shows the directories of the user Cisco.

/lib: Contains libraries that are usually downloaded with software. They are necessary for the programs to work.

/media: Here you might find the mounted USB drives, but it depends on the Linux distribution.

/mnt: When mounting a device in Linux, you use the mnt directory.

/opt: Contains optional software.

/proc: The processes directory contains files for the core operating system (kernel) to work.

/root: For a user, the home directory is /home/username. For the superuser, the home directory is /root.

/sbin: Dedicated to a command that the superuser (root) can run, similar to /bin.

/tmp: Files that are used only temporarily are stored in this directory. The content of the directory is deleted on shutdown.

/usr: Used for sharing files between users.

/var: Here you find files of variable lengths, usually log files of the installed software.

touch, mkdir, -p flag

Create en empty file

(base) shantdari@Darias-MacBook-Air-2 test % ls
(base) shantdari@Darias-MacBook-Air-2 test % touch 1.txt
(base) shantdari@Darias-MacBook-Air-2 test % ls         
1.txt
(base) shantdari@Darias-MacBook-Air-2 test %

-p flag for creating subdir

mkdir –p ~/cisco/platforms/datacenter/nexus

export, parent process variable are not visible to child

By default, any variables that are created in a parent process are not available to the child process. You will need to use the export command for that to be possible. The export command ensures that exported variables in the parent process can be used in the child process (or subshells for that matter).

cisco@cisco:~$ a=test
cisco@cisco:~$ echo $a
test
cisco@cisco:~$ bash
cisco@cisco:~$ echo $a

cisco@cisco:~$exit
cisco@cisco:~$ export a
cisco@cisco:~$ bash
cisco@cisco:~$ echo $a
test

dif

cisco@cisco:~$ diff -u test.cfg test_new.cfg
--- test.cfg 2016-09-12 07:53:04.487466471 -0700
+++ test_new.cfg 2016-09-12 07:53:03.076172461 -0700
@@ -1,4 +1,4 @@
username cisco password cisco
-username sjc password sjc
+username sjc password nyc

-vlan 50
+vlan 10

Env

cisco@cisco:~$ env
<… output omitted …>
USER=cisco
SHELL=/bin/bash
<… output omitted …>
PATH=/usr/local/sbin:/usr/local/bin:/usr/
sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/
local/games:/snap/bin
<… output omitted …>

By default, any variables that are created in a parent process are not available to the child process. You will need to use the export command for that to be possible. The export command ensures that exported variables in the parent process can be used in the child process (or subshells for that matter).

cisco@cisco:~$ a=test
cisco@cisco:~$ echo $a
test
cisco@cisco:~$ bash
cisco@cisco:~$ echo $a

cisco@cisco:~$exit
cisco@cisco:~$ export a
cisco@cisco:~$ bash
cisco@cisco:~$ echo $a
test 

More/less/cat/head/tail

The more command allows you to view the contents of a file one page at a time and requires you to press the spacebar to advance to the next page of contents.

The less command also allows you to view the contents of the file but it allows the user the ability to scroll up and down and perform a keyword search.

The cat command (short for concatenate) is used to stream the entire contents of the file without pausing. It is useful for files with just a few lines. Also, cat is used to add contents to a file.

There are several options to search within files. The head command by default displays the first 10 lines. The tail command displays the last 10 lines of a file.

Password reset for CentOS 6/7

CNTRL+ALT+DELETE -> e -> Change the “ro” parameter to “rw”, delete “rhgb” and “quiet” parameters; add “rd.break enforcing=0” at the end of the line -> CTRL+X to start the system in the single-user mode ->
centos 6

passwd root
  reboot

centos 7

chroot /sysroot
  passwd root
  touch /.autorelabel
  exit
  reboot

https://www.servers.com/support/knowledge/linux-administration/how-to-reset-root-password-on-centos-6-and-centos-7

man

default search is in

manpath

Which

To find where the package is installed

which python

Answer:

/bin/python

Install Sowtware: yum, yast, apt-get

ubuntu - apt-get, SUSE - yast Centos

yum install gcc

Install from rpm

rpm install <name>.rpm

Red Hat Enterprise Linux: Red Hat’s official commercial Linux operating system that is used for training, services, and support. Derivatives include CentOS, Fedora, and Rocky Linux.

Debian: A free and open source operating system that is developed under the Debian project. The most popular derivative is Ubuntu from which there are further derivatives such as Linux Mint and Gn

Red Hat Family

rpm - Install local rpm package
yum and dnf - Download and install a package from repositories
.rpm - File extension
cisco@cisco: ~$ sudo yum install traceroute

cisco@cisco: ~$ sudo rpm –i  <package-name>.rpm

Debian Family

dpkg - Command to install a local .deb package apt & apt-get - Commands to download and install packages .deb - File extension

cisco@cisco: ~$ sudo apt-get install traceroute

cisco@cisco: ~$ sudo apt install traceroute

cisco@cisco: ~$ sudo dpkg –i <package-name>.deb

<, >, »

reroute a command input or output to/from the file

echo "this is test" > /root/reroute_test

cat reroute_test
this is test

& - redirect both STDOUT and STDERR 2> - redirect STDERR only

processes

top - Displays real time processor utilization htop - Displays real time processor utilization in an easier to read format ps - Displays the current user’s active processes ps aux - Displays an exhaustive list of all processes by all users

ps aux | mtr

kill - Sends a signal to end a process by PID kill -9 - Forces the instance of a process to be killed kill -l - Lists all the different possible signals that may be sent with the kill command killall - Sends a signal to end all instances of a certain process pkill - Sends a signal to end a process by name

(base) shantdari@Darias-MacBook-Air-2 test % ps
  PID TTY           TIME CMD
90090 ttys000    0:01.39 -zsh
90424 ttys000    0:00.01 grep WAN Experience
90644 ttys000    0:00.01 ping 8.8.8.8
91899 ttys000    0:00.01 grep BGP.*Agent.*
92392 ttys000    0:00.02 grep .*Web Transaction tests.*Java.*
92499 ttys000    0:00.01 grep .*Endpoint Agent.*test.*
92646 ttys000    0:00.01 grep .*Linux.*
93522 ttys001    0:00.05 -zsh
(base) shantdari@Darias-MacBook-Air-2 test % kill 90644
[2]    terminated  ping 8.8.8.8                                                                                                                                                             
(base) shantdari@Darias-MacBook-Air-2 test % ps        
  PID TTY           TIME CMD
90090 ttys000    0:01.40 -zsh
90424 ttys000    0:00.01 grep WAN Experience
91899 ttys000    0:00.01 grep BGP.*Agent.*
92392 ttys000    0:00.02 grep .*Web Transaction tests.*Java.*
92499 ttys000    0:00.01 grep .*Endpoint Agent.*test.*
92646 ttys000    0:00.01 grep .*Linux.*
93522 ttys001    0:00.05 -zsh

screen

see article https://linuxize.com/post/how-to-use-linux-screen/

screen
Ctrl+a d
screen -r

&& Execute a command if previos is successfull

echo "test1" && echo "test2"

output

test1
test2

Variables

Prefixed with dollar sign when the vale is referenced

vartest = 'test'
echo $vartest

output

test

File Permissions, chmod

File Permissions This topic examines the various file permissions that are used within the Linux system.

Linux operating systems are multi-user

Permissions are based on two factors:

Permissions assigned to a specific user and group

Permissions assigned to a specific action (read, write, execute)

Because it is a multi-user operating system, Linux has a built-in permission mechanism to prevent one user from viewing, modifying or removing another user’s files.

Linux permissions are based on two factors:

Permissions that are based on specific user or group

Permissions that are based on specific user or group

chmod [u, g, o] (+/- [r, w, x]) for each action
Changing Permissions
Value

Description

rwx+ugo

No restrictions on permissions.

u+rwx,go+rx,go-x

The file's owner may read, write, and execute the file. All others may read and execute the file.

u+rwx,og-rwx

The file's owner may read, write, and execute the file. Nobody else has any rights. 

ugo+rw,ugo-x

All users may read and write the file.

u+rw,u-x,go+r,go-wx

The owner may read and write a file, while all others may only read the file. 

u+rw,u-x,go-rwx

The owner may read and write a file. All others have no rights.

Networking

ping - Test connectivity between two nodes. In Linux, ping will run continuously unless manually stopped. Supports options such as on Cisco CLI (hint: man pages). traceroute - Displays the layer 3 hops taken to reach a destination ifconfig - Displays interface information of all interfaces ifconfig eth1 - Displays interface information of a specific interface

netstat - Displays local computer’s connection information, routing table information netstat -r - Displays local routing table (same as the route command) netstat -i - Displays interface statistics

Used to display DNS information such as A Records, MX Records, and CNAMES

 dig google.com

; <<>> DiG 9.10.6 <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 16916
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;google.com.			IN	A

;; ANSWER SECTION:
google.com.		51	IN	A	142.250.186.110

;; Query time: 56 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Fri Aug 11 22:15:37 MSK 2023
;; MSG SIZE  rcvd: 55

To edit network config - edit file nano /etc/network/interfaces

DNS configuration is also stored in a file that is called resolv.conf located in /etc/resolv.conf. This file is auto-generated from files that are located in /etc/resolvconf/resolv.conf.d/.

To regenerate resolv.conf, you can restart networking or use the sudo resolvconf -u command.


<
Previous Post
BGP Community Local AS
>
Next Post
BGP Backdoor