Giter Club home page Giter Club logo

linux-knowledgebase's Introduction

Linux-knowledgebase

linux-knowledgebase's People

Contributors

zesttec avatar

Watchers

 avatar

linux-knowledgebase's Issues

Command line

Table of contents generated with markdown-toc

ls

ls -a: list all files including hidden files.
ls -l or ls -la: list all files and their permission info, etc.
ls -lh display the size in a human-readable way

grep

grep -r "xxx" .: search string "xxx" under current directory.

Redirection

Redirection (link)

redirect the output to a file:
SomeCommand > SomeFile.txt
Or if you want to append data:
SomeCommand >> SomeFile.txt
If you want stderr as well use this:
SomeCommand &> SomeFile.txt
or this to append:
SomeCommand &>> SomeFile.txt
if you want to have both stderr and output displayed on the console and in a file use this:
SomeCommand 2>&1 | tee SomeFile.txt
(If you want the output only, drop the 2 above)

mkdir

mkdir -p aa/bb/cc
'-p' guarantees the dirs along the path can be created if it doesn't exist.
Without '-p', if you use "mkdir aa/bb/cc" while there is not aa dir or bb dir, an error would be posted and cc dir can not be created.

Ref: https://www.runoob.com/linux/linux-comm-mkdir.html

Linux User Management

Linux Users and groups

Create a new user and set its password:

#You need to apply the commands with root permission( with sudo or using sudo su - to switch to root account ) most of the time.

  • useradd newusername
  • passwd newuser'spassword

To verify new user is successfully created:

  • su newusername
    switch to the new user account, type corresponding password. If you login, then it successes! To log in back to original account, you can just use exit command.

Once a new user created, it entry is added to /etc/passwd file like:
newusername:x:1001:1001::/home/newusername:
Username:Password:UserID(UID):GroupID(GID):UserInfo:HomeDirectory:Shell

What are these fields:

  • Username: User login name used to login into system. It should be between 1 to 32 charcters long.
    Password: User password (or x character) stored in /etc/shadow file in encrypted format.
  • User ID (UID): Every user must have a User ID (UID) User Identification Number. By default UID 0 is reserved for root user and - - UID’s ranging from 1-99 are reserved for other predefined accounts. Further UID’s ranging from 100-999 are reserved for system accounts and groups.
  • Group ID (GID): The primary Group ID (GID) Group Identification Number stored in /etc/group file.
  • User Info: This field is optional and allow you to define extra information about the user. For example, user full name. This field is filled by ‘finger’ command.
  • Home Directory: The absolute location of user’s home directory.
  • Shell: The absolute location of a user’s shell i.e. /bin/bash.

Add home directory for new user:
useradd -d /home/HomeDirectoryName newusername

Change the ownership of dirs or files:

chown newusername -R a/b/c/ means giving newusername the ownship of directory a/b/c/ and all files inside it.
chown newusername a/b/c/ means giving newusername the ownship of directory a/b/c/.

Created a new group

groupadd newgroupname.
Groups information is stored in /etc/group

Change the group ownership of a file or directories.

chgrp [-R] groupname fileORdirectory -R option means to change the group ownership recursively of files and directories.

You can also pass multiple files to chgrp command as arguments:
chgrp groupname file1 file2 file3

Reference:
https://www.tecmint.com/add-users-in-linux/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.