Linux Basics/Basic commands

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Root vs user permission[edit | edit source]

  • [root@ubuntu ~]# - root permission
  • [user@ubuntu ~]$ - user permission

User can execute things with root permission that the user wouldn't do with base permission likeapt install, but using sudo does the same job as if you were in root. Linux Basics/User management (System administrator) chapter dives deeply into this topic.

Commands[edit | edit source]

  • <command> --help: it will display all the switches for the command
  • cd: change directory (→ cd .. = it will go back by one folder/directory)
  • pwd: print working directory – it'll display which folder you're in right now
  • w: it shows who are logged in and what they are doing (w <username> displays the particular user's activity)
  • who: it displays only the tty interface, the date and ip address with the username
  • ls: listing files in a directory
    • ls -a: it lists all the hidden files aside the non-hidden ones
    • ls -A: same as previous, but it lacks . and .. (. means the current folder, .. means previous folder)
    • ls -l: detailed directory list
    • ls -al: based on the commands above: detailed directory list + hidden files with . and ..
  • exit: it'll quit the user from the shell and close the shell
  • sudo <command>: you can do commands as superuser
  • mv: move, moving from A to B: syntax: mv <source> <destination>. It can be used for renaming too.
  • mc: midnight commander's command (you have to install it, because most distros don't contain mc by default)
  • touch file: creating "file" named file
  • echo something: "something" will be directed to the echo's standard output.
  • nano file: editing "file" named file with nano (by default on some distros it's not installed, so you have to install it)
  • less file: outputting "file" named file to the terminal, but you can move in the word viewer, and you can quit from it by pressing q
  • rm: remove, delete
    • rm -r: recursive, so the rm command will delete everything that is given
    • rm -f: force, so without any arguments the folder will be deleted
    • rmdir: folder deletion, but rm -rf is simpler to delete a folder with files.
  • mount: connecting devices
  • umount: disconnecting devices
  • ln: creating link (hard-link)
  • df = disk free = it says how many free spaces are on each partition
  • du = disk usage; you have to give parameters, else it's gonna list all the directories
    • du /home: it's gonna list the content of /home and the usage of the folders
    • du -h it says which folder and file how many kB, MB, GB does it take, if we won't put this, it's gonna list everything in bytes
    • du -s summarizes (it takes every folder as one, and it'll write the sum of their size)
  • free = free memory and swap space
  • top (black and white) / htop (color) = it displays the currently running apps (like Task Manager in Windows)
  • uname = displays info about the system, -a switch tells everything about the kernel

Output in Manjaro:Linux manjaro 5.6.11-1-MANJARO #1 SMP PREEMPT Wed May 6 10:20:32 UTC 2020 x86_64 GNU/Linux

  • ntpdate <server> = it's gonna update your system's time based on the time server address you gave (like time.nist.gov => ntpdate time.nist.gov)
  • uptime = how long have your system been running, and how much it's loaded
  • netstat = network statistics
  • man = It opens the manual pages of the command, short and straightforward description
  • info = same as man, just it's more common in Red Hat systems

Network managemenent[edit | edit source]

  • ifconfig = ip address, network settings, amount of sent and received packages
  • iwconfig = same as ifconfig, just this is for wireless settings
  • ping (pinging an IP address) : ping www.google.com ; ping -c 3 www.google.com (we can give after the -c switch how much packets do we want to send to a page)
  • ifup = interface up – it runs a script when it's enabled (e.g. ifup eth0 -> it enables eth0 interface)
  • ifdown = interface down – same as ifup, just here we disable the interface e.g. ifdown eth0
  • ifstatus - interface status
  • ifstat – it monitors the upload/download speed of the interfaces

User management[edit | edit source]

  • adduser/useradd – user creation
  • userdel – user deletion
  • chmod - change mode - we can set the permissions for the files and directories(Linux Basics/Filesystem, permissions has more information on this)
  • chown – change owner
  • usermod – modifying user

package management commands: dpkg, rpm, apt, yum, dnf, pacman, zypper stb.

Other commands[edit | edit source]

  • clear – clears terminal
  • chroot – changing root folder
  • kill – killing/terminating process based on PID (ps -A displays that)
    • kill -9 – kills every subthread
    • killall - kills the list's all elements but kill -9 @(...) is easier
  • halt - computer shuts down, but its PSU still goes(in case of ATX v2 PSUs)
  • shutdown / sudo init 0 – computer shuts down completely
  • reboot – computer reboots – sudo init 6
  • /bin/bash – bash command prompt
  • service – we can start/restart services running on the computer
  • systemctl – same as service
  • cron: computer does things without your input (in intervals, startups, shutdowns), cron daemon runs these (hourly, daily, weekly..)
  • crontab: user's own cron setting
    • crontab -e: editing crontab

/etc/skel folder: the content of this folder goes to the new user's home folder (skel = skeleton)

/etc/sudoers file: those users who can use sudo. (Linux Basics/Filesystem, permissions explains it in depth)