SageTV Community

SageTV Community (http://forums.sagetv.com/forums/index.php)
-   SageTV Downloads & Instructions (http://forums.sagetv.com/forums/forumdisplay.php?f=54)
-   -   Basic Linux Commands and Usage (http://forums.sagetv.com/forums/showthread.php?t=62725)

SageWizdom 11-27-2015 08:39 PM

Basic Linux Commands and Usage
 
For folks who want to try Sage 9 on Linux, but are less than comfortable with the Unix command line, I've attempted to put together a list of commands below that may be useful to general users.

General Navigation:
Getting around on a Linux machine is very similar to the windows command line.

cd - change the current directory. If you run cd with no arguments, it returns you to your login / user directory. Typically "/home/<username>"

ls - list directory contents. This is equivalent to the "dir" command in the dos command line. It is worth noting that filenames that start with a "." are hidden by default. "ls -a" will show all files including hidden files. "ls -l" will display the files in list form. "ls -lh" will display sizes in a human readable form (kb/mb/etc). I tend to use "ls" "ls -alh" or "ls -lh"

pwd - print working directory. This will list out the full path to the directory you are currently in.

mkdir - make directory. This will create a new directory of the name supplied

rm - remove. Similar to the "del" command in the dos command line, rm is very powerful. To delete directories recursively, "rm -r <name>" can be used. a common usage is "rm -rf <name>". The "f" causes the rm command to not prompt for deletion. NEVER type "rm -rf .*" because in unix, the directory above is called ".." the previous command matches every directory on your computer and will delete everything.

cp - copy. Similar to the windows copy command. An example "cp <file name> <newcopy>"


mv - move. This can be used to both move a file between directories and to rename a file. Examples include "mv <file name> <new path>" "mv <file name> <new path/new name>" and "mv <file name> <new name>"

chmod - change file mode / access control list. There are many ways to use this command, but I prefer the slightly more human readable forms. An example is "chmod a+r <filename>". In this case, you can have an "a", a "g" or a "u" before the + sign. These let you change the permissions for (a)ll users, the (g)roup or the (user). There can be a "+" to add a permission and a "-" to remove a permission. After the +/- sign you can adjust the (r)ead, (w)rite and e(x)ecute permissions. ex. "chmod a+rwx filename" or "chmod g-r filename"

chown - change the file owner. If you've accidentally created a file as a root / super user, but want it to be generally only accessible by you, you would chown the file, then chmod it to only allow the user to read, write or execute it. When used with a ":" you can also specify a new group. example "chown user:group filename"

chgrp - change the group. This changes the group affiliation of a file. This can be done simply with chown.



Admin Commands

sudo - (s)uper (u)ser (do). This executes the following command as the super user. This is like running a dos shell as the administrator. sudo can be restricted to specific users or files, but in many cases, the default created user (ubuntu 14.04 server) will have full sudo abilities. sudo is recommended instead of logging in as root or another admin user.

sudo reboot - reboot the computer .... immediately. You must be a privileged user to run this.

sudo shutdown - shut down the computer ... I believe this also happens "now" but do not want to test it. sorry.

passwd - change your password. First you will be prompted for your current password, then you will get to chose a new password.



Accessing & Finding Files

nano - a very simple command line editor. While wars have been waged over which editor is better (vi vs emacs), for new Linux users, I recommend nano. It provides a list of all of its commands at the bottom so you don't have to remember, and it is fairly forgiving of mistakes.

cat - print a file to the screen. This is like the dos "type" command.

less and more - basic scrolling file displays. more acts the same in Linux as it does in dos, display one screens worth of data at a time. less is a slightly enhanced version that allows you to scroll up and down with the arrow keys, or page up and down the the page up / page down keys. Both will quit when you press the "q" key.

<command> -h or --help - provide help. This is the unix equivalent of the dos "/?" after a command.

man <command> - provide a basic manual of the command usage and syntax. man has similar functionality to the less command and allows you to both page and scroll up and down.

find - find a file. This can be very powerful for finding files on your system. "Where is that darn hdhomerun_config executable?" It allows wildcards in the name. The first parameter is where to start looking. For example, to find anything staring with "hdhome" anywhere on the system "find / -name 'hdhome*' 2>/dev/null". To find anything with "sage" in the current directory "find ./ -name 'sagetv*' 2>/dev/null".

echo - repeats the text in quotes and is useful for appending text to a file. For example "echo 'this is text' >> file.txt" appends the text to a file if it exists, or creates the file if it does not. NOTE: be careful of using one '>' versus two '>>'. Two greater than signs will append the text to a file. Using a single will always destructively overwrite your file with the text.

IP Commands

ifconfig - list ip information. This is equivalent to the "ipconfig" command in a dos terminal. In linux, your wired ethernet port is commonly "eth0" so you might call this as "ipconfig eth0" to only display information about that link.

lsof -i - list open ports. The lsof command generally lists open files, the -i option specifically lists open ports. When run you should see some of the common SageTV ports open (42024, 31099, 7818, etc). More info here (https://danielmiessler.com/study/lsof/)

cat /etc/resolv.conf - display a list of dns servers. This is a compound command which prints to the screen a file containing your configured DNS servers.

ping <ip> - ping the ip/host. This is exactly the same as ping in windows.

traceroute <ip> - show the timing to an ip/host. This is the exact same as the "tracert" command in windows


Processes and Process Management

ps - show running processes. I tend to like "ps aux" which shows all user processes. A common pattern is to run "ps aux | grep <command>" to show you if any of the command you are looking for are running. ex. "ps aux | grep java"

kill - kill a process. This command can kill a process that is running out of control. Use the "ps" command to get the process number.

Ctrl-C - kill the running process. Most processes when they run, run in the foreground of your shell, taking the place of the command shell. Pressing Ctrl-C kills the program and returns to the shell. Any non saved changes are lost.

Ctrl-Z - pause (stop) the running process. Most processes when they run, run in the foreground of your shell, taking the place of the command shell. Pressing Ctrl-Z pauses the program and returns you to the shell. Your program is still in memory but is not running. If there are other ways to interact with it (gui, network, etc) they generally will not respond.

jobs - displays paused and background processes in the current shell. If you have used Ctrl-Z to pause multiple applications, jobs will display the names of all of them along with job numbers. You can then use "fg" or "bg" to move them to the foreground or background.

fg # - move a paused process to the foreground. By default it will move job 1 to the foreground. If you specify a job number, you can move any paused job to the foreground. The job number is optional.

bg # - move a paused process to the background. By default it will move job 1 to the background. If you specify a job number, you can move any paused job to the background. The job number is optional. An example is starting the SageTV client, then moving it to the background, so that your terminal is available for other work, but client GUI is active.

& - appended to the end of a command, this causes a command to automatically run as a background process. For example. "./sageclient.sh &" would run the sageclient script in the background.

nohup - immune to hangup. Originally from the days of modems, this allows a background application to continue running, even after the user terminal disconnects or the user logs out. This would be useful if running sage or the sage client from the command line and you want it to keep running even if the terminal is closed. An example is "sudo nohup sageclient.sh &" This runs the sageclient script in the background as the superuser, and keeps it running if the terminal is closed.


(TODO) finish the below
Device Management

mount
umount

ln - symbolic link

which
whereis


What commands are missing that people would like to see, please respond in the comments.


All times are GMT -6. The time now is 06:52 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.