Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Linux Unix - GRU File Commands

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

linux unix / GRU file commands

what -- does
Use -- to separate options from parameters.
for example
Rm -- -galondel.png

PWD - print working directory


example

─(root 💀 kalillocal)-[~/Downloads/lolapi]
└─# pwd

/root/Downloads

● . (current directory). This is the directory you are currently in.


● .. (parent directory). Takes you to the directory above your current.
● ~ (home directory). This directory defaults to your “home
directory”. Such as /home/pete.
● - (previous directory). This will take you to the previous directory you
were just at.
cd ~ is like cd without : ~

ls - local dictionary

exa
─(root 💀 kalillocal)-[~/Downloads/lolapi]

─# ls -a
. .. .lal.txt lal.txt

–-# ls - l full show of file

from left to right

file permissions, number of links, owner name, owner group, file size,
timestamp of last modification, and file/directory name.
for example

file permissions number of links owner name owner group file size
timestamp of last modification

drwxr-x--- 7 pete penguingroup 4096 Nov 20 16:37

Directory name
Desktop

you can use ls -la to combine both commands -l , -a


more examples
● ls -R: recursively list directory contents
● ls -r: reverse order while sorting
● *** # ls -t: sort by modification time, * newest first *

┌──(root💀kalillocal)-[~/Downloads/laloli]
└─# ls -t
indo.txt lal.txt
Mar 9 12:26 Mar 9 11:40

TOUCH
you can create a file with it.
—# touch command on existing file will update the
timestamp.
after touch .lal.txt

File command
shown the format / kind of file.
$ file banana.jpg

┌──(root💀kalillocal)-[~/Downloads/laloli]
└─# file banana.jpg
banana.jpg: directory
its dictionary not jpg file its not like in windows file sys

Display Contact of file


cat
cat to show few smull files together

more
more to see contact of file text

less
less to see contact with extended options

-------------------------- global—---------------

grep Regular Expressions


what is grep ?
grep is the best way of filtering data display

Beginning of a line with ^

file1 | grep ^start


start start with start

bob not starting with start

End of a line with $

file1 | grep ?$
this line ends with ? mark ?
this line does not end with ? Mark !
file1 | grep d[iou]g
would match: dig, dog, dug

file1 | grep d[^iou]g


wouldn't match: dig, dog, dug

ctrl-R - to search in the terminal history

$ “whatis” to check description of application


–#history : to see all the commands

Alias
alias to change recognition of command fo ex:
alias foobar='ls -la' to call (ls -la) command as “foobar”

.bashrc - to save the alias


remove alias - unalias foobar

Manipulating file permission

d | rwx | r-x | r-x


Each character represent a different permission:
● r: readable
● w: writable
● x: executable (basically an executable program)
● -: empty
file permission
So in the above example, we see that the user pete has read, write and
execute permissions on the file. The group penguins have read and execute
permissions. And finally, the other users (everyone else) has read and
execute permissions.
‫ ביטים‬3 ‫הנחות יסוד למעלה לכל אחד יש‬
add permission to user on file myfile $ chmod u+x myfile
delete permission to user on file myfile $ chmod u-x myfile

● 4: read permission
● 2: write permission
● 1: execute permission

user group other


{1+2+4} , {2+1} , {4+1} 7,3,5 = all,w-x,r-x
user group other
{4+2} , {1+2} , {4+2+1} 6,3,7 = r-w, w-x , all

Rm remove
rm -r remove directory and the stuff within it
rm -d remove empty directories
rm -f force remove

Manipulating files

std
echo to display input on terminal
now we use >

instead of making terminal output we want to insert the txt into a


text file named peanuts

echo Hello World > peanuts.txt


cat peanuts.txt
- hello world
the >> key would add text to file instead of replacing the text

cat < talmat.txt > banan.txt


copies contact from talmat.txt to banan.txt

ls <talmat.txt > banan.txt


copies ls output and talmat.txt contact to banan.txt

cut command

display text in file by condition

cat talmat.txt
hello

for example
cut -c 2 talmat.txt

- a

explain:
cut -c [index] allow us to
display key by index number

User Management
display list of users
cat /etc/passwd
let's explain this
root:x:0:0:root:/root:/bin/bash
1. Username
2. :encrypted User's password You can see many different symbols that
are in this field, if you see an "x" that means the password is stored in
the /etc/shadow file, a "*" means the user doesn't have login access
and if there is a blank field that means the user doesn't have a
password.
3. user id (uid)
4. group id
5. GECOS field - This is used to generally leave comments about the
user or account
6. User's home directory
7. User's shell - you'll probably see a lot of user's defaulting to
bash for their shell

display list of pass****


cat etc/shadow/

1. Username
2. Encrypted password
3. Date of last password changed - expressed as the number of days
since Jan 1, 1970. If there is a 0 that means the user should change
their password the next time they login
4. Minimum password age - Days that a user will have to wait before
being able to change their password again
5. Maximum password age - Maximum number of days before a user
has to change their password
6. Password warning period - Number of days before a password is
going to expire
7. Password inactivity period - Number of days after a password has
expired to allow login with their password
8. Account expiration date - date that user will not be able to login
9. Reserved field for future use

cat /etc/group

1. Group name
2. Group password - there isn't a need to set a group password, using an
elevated privilege like sudo is standard. A "*" will be put in place as
the default value.
3. Group ID (GID)
4. List of users - you can manually specify users you want in a specific
group
User Management Tools
useradd bob
add new user and creating entry in /etc/passwd
sets up default group and adds an entry to the /etc/shadow
Removing Users

userdel bob

Changing Passwords

passwd bob

This will allow you to change the password of yourself

VI .
the vi is our tool for editing files

● Press the ESC key for normal mode.


● Press i Key for insert mode.
● Press :q! keys to exit from the editor without saving a file.
● Press :wq! Keys to save the updated file and exit from the
editor.
● Press :w test.txt to save the file as test.txt

nano is also good way to edit file


save and exit with ctrl x

wc -w to count words in text file

You might also like