| English | 日本語 |

Tokyo Linux Users Group

Filenames

Hidden Files

Q. How do you “hide” a file or directory?

Name the file with a . at the beginning:

$ touch .hidden

Q: How do you list such files/directories?

Use the -a option:

$ ls -a

Contributor(s)
Travis

Dash Files

Q: How can you remove a file named -r?

Use -- to tell commands where options end:

$ touch -- -r
$ rm -- -r
$ rm ./-r

Contributor(s)
Bruno
Mattia
Quiz(es)
Meetings:2014:05

Glob Files

Q: How can you remove a file named * or ?

Use backslashes to escape such characters:

$ touch \* \?
$ rm \* \?
$ rm '*' '?'

Contributor(s)
Daniel
Quiz(es)
Meetings:2014:05

Globs

Q: How can .??* be useful?

It displays hidden files with at least two characters after the dot:

$ touch .1 .un .deux .trois
$ echo .*
.  ..  .1 .deux  .trois  .un
$ echo .?*
.. .1 .deux  .trois  .un
$ echo .??*
.deux  .trois  .un

Contributor(s)
Bruno
Quiz(es)
Meetings:2014:05

Permissions

-rwxrwxrwx

Q: How can you find all world-writable files/directories in $HOME?

find is used for recursion:

$ find $HOME -perm -2 ! -type l -ls

Q: How can you fix the permissions for all files found?

Use -exec chmod:

$ find $HOME -perm -2 ! -type l -exec chmod o-w {} +
$ find $HOME -perm -2 ! -type l -exec chmod o-w {} \;

What is the difference between “+” and “\;” notations? Why would you choose one over the other?

Contributor(s)
Travis
Bruno
Quiz(es)
Meetings:2014:05

-rwsr-x---

Q: What do permissions -rwsr-x--- signify?

Q: When would permissions like this be useful?

Contributor(s)
Travis
Quiz(es)
Meetings:2014:05

-rwxr-sr-x

Q: What do permissions -rwxr-sr-x signify?

Q: When would permissions like this be useful?

Contributor(s)
Travis
Quiz(es)
Meetings:2014:05

drwxrwsr-x

Q: What do permissions drwxrwsr-x signify?

Q: When would permissions like this be useful?

Contributor(s)
Travis
Quiz(es)
Meetings:2014:05

drwxrwxrwt

Q: What do permissions drwxrwxrwt signify?

Q: When would permissions like this be useful?

Contributor(s)
Travis
Quiz(es)
Meetings:2014:05

/etc/hostname

Q: How can you update /etc/hostname as a non-root user?

$ ls -l /etc/hostname
-rw-r--r-- 1 root root ... /etc/hostname
$ cat /etc/hostname
changeme

Use sudo tee:

$ echo tlug | sudo tee /etc/hostname

Alternatively:

$ sudo bash -c 'echo tlug > /etc/hostname'

Contributor(s)
Travis
Quiz(es)
Meetings:2014:05

Filesystem

rm

Q: How and when could rm not free disk space?

Contributor(s)
Bruno
Quiz(es)
Meetings:2014:05

Q: What is the difference between ln and ln -s?

Q: When would you use each type of link?

Contributor(s)
Bruno
Quiz(es)
Meetings:2014:05

Pipes

Standard IO

Q: How can you run a program and not display STDERR (bash)?

Redirect STDERR to /dev/null:

$ somejavaprogram 2> /dev/null

Q: How can you redirect both STDOUT and STDERR to a file?

$ somejavaprogram > file.log 2>&1

Q: What are doing exactly the following lines?

TMPFILE=/tmp/$$-test
exec 3>&1 >${TMPFILE}
echo ichi
exec 1>&3 3>&-
echo ni
cat ${TMPFILE}

Contributor(s)
Travis
Bruno
Quiz(es)
Meetings:2014:05

Named Pipes

Q: How do you create a named pipe?

$ mkfifo tlug
$ ls -l tlug
prw-r--r-- 1 tokyo tokyo 0 May 10 15:00 tlug

Q: How do you use named pipes?

Treat them like files. On the command line, use redirection:

one$ echo 'Hello, TLUG!' > tlug
two$ cat < tlug

Nothing is written to disk!

Q: Why use named pipes?

Contributor(s)
Travis
Quiz(es)
Meetings:2014:05

Processes

Slow System

Q: How can you determine which program is slowing down your system?

Q: How can you terminate it?

$ kill $PID  # sends TERM signal to $PID

Q: What if that doesn't work?

$ kill -9 $PID  # sends KILL signal to $PID

Contributor(s)
Travis
Quiz(es)
Meetings:2014:05

Unmount Fail

Q: If you try to unmount a filesystem and get an error about open files, how can you solve the problem?

Use lsof to show which processes access a directory/file:

$ lsof /mnt/stick

Use fuser to show which processes use the filesystem:

$ fuser -v -m /mnt/stick

Contributor(s)
Travis
Quiz(es)
Meetings:2014:05

Processes/Zombies

Q: What is a process? How do you create one? What is the relationship between a child process and a parent process?

Q: Who is the ancestor of all processes on your system? How could it be “alive” itself?

Q: What is a zombie process?

Q: Why are they bad?

Q: How do you get rid of one?

Send a SIGCHLD signal to the parent process:

$ kill -s SIGCHLD $PID

If that does not work, the parent process must be killed.

Contributor(s)
Travis
Bruno

Substitution

Q: What does the following do (bash)?

$ program --in1 <(makein in1.txt) \
--in2 <(makein in2.txt) \
--out1 out1.txt --out2 out2.txt \
> stdout.txt 2> stderr.txt

Contributor(s)
Travis
Quiz(es)
Meetings:2014:05
Reference(s)
http://vincebuffalo.org/2013/08/08/the-mighty-named-pipe.html

Network

Infiltrated

Q: How can you determine which program is making your fiber-modem blink?

lsof is useful for listing network connections as well:

$ lsof -i

netstat is also a useful utility:

$ netstat -pt

Contributor(s)
Travis
Reference(s)
http://www.danielmiessler.com/study/lsof/

Ding

Q: If your terminal bell works, what standard utilities can you use to get an alert when somebody visits your website?

tail -f follows files, and sed can insert a BEL:

$ tail -f /var/log/nginx/site.access.log \
| sed 's/^/\a/'

Contributor(s)
Travis