Linux Shell
On that page you find some tips on how to do things from the command line on linux.
Index
Links
Batch chmod
Has you must know by know, I'm just learning Linux, so I won't be able to tell you how many variants there are of Shell languages out there. In fact I don't even know what version of Shell I've been using myself.
Anyhow I had to change some file permissions the other day when deploying that
TWiki thing I'm using to run that web site. To do that I used the following shell script:
#!/bin/bash
folders=`find -xtype d`
for folder in $folders ; do
chmod -v 775 "$folder"
done
It gets the list of subdirectories put it in a variable and then executes a
chmod for each of them. Later on I find out that I could have done the same thing in one single line:
find . -type d -exec chmod 775 {} \;
I haven't tried that yet though.
Thanks to Daniel for helping me on that one.
Find command
Find files in the current directory that do not contain '.' character besides the first character:
find . -maxdepth 1 -type f -regex '\.[^\.]*'
Find all the file from the current directory with .conf extension and containing the string "LoadModule".
Grep flag -H prints the name of the file and -i flag makes the search case insensitive search:
find . -type f -regex .*\.conf -exec grep -H -i LoadModule {} \;
Find all files with a name matching *LeftBar* but not matching WebLeftBar*:
find . -name "*LeftBar*" ! -name "WebLeftBar*"
Find all files with a name matching favi* and display their properties:
find . -name "favi*" -exec ls -l {} \;=
Read more on
linux.com
Downloading
Want the download a file? Just use:
wget <url>
Here again thanks to Daniel.
Debian Aptitude
I had to use that to install missing packages while setting up TWiki on a Debian machine.
- To list installed packages:
dpkg -l
- Get the version of appach2 installed on your machine:
dpkg -l | grep apache2
Symbolic link
To create a symbolic link with the same name as the original final in the current directory:
ln -s /etc/apache2/mods-available/auth_ldap.load
Create an empty file
Just do:
touch <filename>
To do deltree
rm -rf <dirname>
Console text editor
- Bad old
Vi .
-
fte: I used it on a Debian it was ok but nothing exciting.
-
mc: Midnight Commander a clone of Norton Commander. It's rather good and does syntax highlighting for my Perl scripts.
Handle tgz file
- First deflate using
gzip: gzip -d MyFile.tgz
- Then using
tar: tar -xf MyFile.tar
Memory information
cat /proc/meminfo
Run all daily cron jobs
for f in /etc/cron.daily/*; do echo $f; $f; done
Free disk space
df -hl
df means diskfree
-h means human readable
-l means local disks only
Debian shell prompt
To display the working directory in your shell prompt:
export PS1=" \u@\h:\w\$"
export PS1="\h:\w #"
Send file through FTP
Do something like:
scp ~/localdir/my.file user@example.com:~/ftpdir/my.file
Process status
See
PS command.
ps -Al
The column
UID gives you the user ID for processes. To get the corresponding user name do
cat /etc/passwd.
Kernel module
We are using the
psmouse module as an example.
- Get information about a module
-
modinfo psmouse
- Remove a module
-
modprobe -r psmouse
- Add a module
-
modprobe psmouse
- Add a module with argument
-
modprobe psmouse proto=imps
- List modules
-
lsmod