Linux Commands part - 2 #kali

$file images.png

output-

Dimensions file type 8 bit color map

$less file.txt

this command shows overwhelm text in one screen at a time.

$sudo apt install imagemagick

$identify images.png

Gives the properties of the images etc...

$mkdir -p /home/Desktop/maverick/Documents/MyDocuments/

This command gonna create sub-directory.

$ mkdir -p Soumya/Documents/Kali.pdf/ | touch mk.txt

Find

$$ find /home -name puppies.jpg

$$ find /home -type d -name MyFolder


$help


$man


$whatis ls
Oneliner help this command will explain the command in one line.

18. alias

Sometimes typing commands can get really repetitive, or if you need to type a long command many times, it’s best to have an alias you can use for that. To create an alias for a command you simply specify an alias name and set it to the command.

$ alias foobar='ls -la'

Now instead of typing ls -la, you can type foobar and it will execute that command, pretty neat stuff. Keep in mind that this command won't save your alias after reboot, so you'll need to add a permanent alias in:

~/.bashrc

or similar files if you want to have it persist after reboot.

You can remove aliases with the unalias command:

$ unalias foobar

Standard OUTPUT
cat Hello, World! > Data.txt - overwrite
cat Hello, World! Damm >> Data.txt - >> not overwriting

Stdin 
Standard Input
$cat <Data.txt> Data1.txt
Data.txt contains data copy in Data1.txt

$ls <Data.txt> Data1.txt
Data1.txt contains list of files.

$ pwd < Data.txt > Data1.txt
Data1.txt contains current working directory path text.
mkdir wd <c.txt> p.txt
ls -la -o Data.txt
ls -la Data.txt

Standard Error

$ ls /fake/directory 2> /dev/null
For no output file..

Pipe AND Tee
$ ls -la /etc
$ ls -la /etc | less 
$ ls | tee peanuts.txt
You should see the output of ls on your screen and if you open up the peanuts.txt file you should see the same information!
$ ls > info.txt
this will not show info on screen but it will store in info.txt file.
 
 Environment
$echo $HOME
$echo $USER
$env
shows the environment variables.
$echo $PATH
 
Cut Command 
1.
$echo 'Welcome To Delhi. Delhi is the place of dilwale.
$cut -c 2 State.txt
e
Above command extract characters.
$cut -c 5 State.txt
o
 
2. 
$ cut -f 2 -d "." State.txt
Delhi is the place of dilwale
Above commands gives the output after the  delimeter (.).
 


 Paste here hanuman ji message from kali linux machine.
29 FEB 2024


Head & Tail
$head Radha.txt
head -n 15 R.txt
This command gives the first or few lines of text
$tail Radha.txt
This command gives the last few lines of text 
 
Expand u/s Unexpand
1.Expand - converts tabs to spaces.
$expand -t 4 file.txt
$ expand sample.txt > result.txt
2.Unexpand - converts spaces to tabs.
$unexpand -t 4 file.txt
$ unexpand -a result.txt

Sort
$sort f1.txt
sort the text
$sort -r f1.txt - reverse sort the text.

And also sort via numerical value:

$ sort -n file1.txt

bird
cat
cow
elephant
dog

Translate
tr -d "abc" - # Deletes characters a, b, and c
tr -u '[:lower:]' '[:upper:]'  # Translate lowercase to uppercase
tr -l '[:upper:]' '[:lower:]'  # Translate uppercase to lowercase

Examples:

  • Translate all uppercase characters to lowercase:

    bash
    echo "HELLO" | tr '[:upper:]' '[:lower:]'
  • Delete all digits from input:

    bash
    echo "Hello123" | tr -d '[:digit:]'
  • Replace spaces with tabs:

    bash
    echo "Hello World" | tr ' ' '\t'
  • Remove all non-alphanumeric characters:

    bash
    echo "Hello, world!" | tr -cd '[:alnum:]'
  • echo "maverick" | tr a-z A-Z
  • echo a-z A-Z
  • maverick
  • Maverick

uniq (Unique)

he uniq (unique) command is another useful tool for parsing text.

Let's say you had a file with lots of duplicates:


reading.txt
book
book
paper
paper
article
article
magazine
$ uniq reading.txt

book
paper
article
magazine
$uniq Not_Unique_text.txt 
Anshu
rishu
piyush
ashish

$uniq -d names.txt - just get duplicate values.


wc (Word Count)and nl (Number Lines)
┌──(maverick㉿kali)-[~/Desktop/TXT-FILES]
└─$ wc F1.txt
 3  3 19 F1.txt
#F1.txt contains these three names without numbers Anshu Piyush and Rishu
┌──(maverick㉿kali)-[~/Desktop/TXT-FILES]
└─$ nl F1.txt 
     1 Anshu
     2 Piyush
     3 Rishu

Grep
$ grep Piyush F1.txt

 Debian package and rpm        
           
Install a package Debian: 
$ dpkg -i some_deb_package.deb 
RPM: 
$ rpm -i some_rpm_package.rpm 
The i stands for install. You can also use the longer format of --install. 
Remove a package
Debian: 
$ dpkg -r some_deb_package.deb RPM:
 $ rpm -e some_rpm_package.rpm 
Debian: 
r for remove RPM: e for erase List installed packages 
Debian: $ dpkg -l RPM: $ rpm -qa

User Management
$ cat /etc/shadow - view the protected file
How to create a user in kali linux?
$sudo useradd bob

How to delete user in kali linux?
$sudo userdel bob

2. System V Service

All service commands

There are many command line tools you can use to manage Sys V services.

List services

$ service --status-all

Start a service

$ sudo service networking start

Stop a service

$ sudo service networking stop

Restart a service

$ sudo service networking restart
Permissions

Processes



4. Add the Scripts Directory to Your PATH

run the script from the anywhere in the terminal

To easily run your scripts from any location in the terminal, add the scripts directory to your PATH. Open your .bashrc file:

bash
nano ~/.bashrc

Add the following line at the end of the file:

bash
export PATH=$PATH:~/scripts

OR

echo 'export PATH=$PATH:~/scripts' >> ~/.bashrc source ~/.bashrc

Save and close the file, then reload your .bashrc:

bash
source ~/.bashrc

How to check which shell u are running in kali?
echo $SHELL
echo $0




Gnome-Screenshot
#linuxcommands

Comments

Popular posts from this blog

How To Customize Linux Bootloaders ... #customization #linuxcustomization #kalilinuxcustomization

"Colorful Command Line: How to Add lolcat to Your Linux Commands"