Jump to content

FreeBSD - Helpful tricks


Recommended Posts

Hey @ all,

I hope a thread like this doesn't exist right now!

Introduction:

Here u'll find some basics you should know, and some things which makes your life easier!

So let's go:

First of all, the command-line! If you often uses putty (or s.th. else) it helped me a lot to change the default prompt!

Here my favorite:

Spoiler

291517comando.png.ea06da395d4b7ec60119b9

You only have to edit the .cshrc file in your <user> (for example /root or /home/<user>) directory!

Uncomment the given prompt line, or delete it and put the following instead:


set prompt = "%{033[31m%}%n %{033[1;33m%}%~ %{033[0m%}>"

Second thing is the SCP Service! Most of u know "winscp" which is based on the unix scp service!

Spoiler

With this, you easy can transfer files between you servers and you don't have to copy it first on your computer!

For example, we take the file.tgz from out SOURCE server, to our system into the direcory we are at the moment:


scp -P <port> <user>@xxx.xxx.xx.xxx:<path_to_file> <path_where_to_save_file>

If you are using a SSH-Key on the external server, you have to edit your command, and add the .ppk file to it:


scp -P <port> -i <path_to_private_key> <user>@xxx.xxx.xx.xxx:<path_to_file> <path_where_to_save_file>

(the ppk should have 600 rights!)

If you need an example:

Spoiler

Take game.tgz from 10.2.0.1 in the /home directory to /usr/home



scp -P 22 [email protected]:/home/game.tgz /usr/home/

Take game.tgz from 10.2.0.1 in the /home directory to /usr/home, with the ppk in /home/my.ppk



scp -P 22 -i /home/my.ppk [email protected]:/home/game.tgz /usr/home/

Here some helpful commands:

Spoiler

-----------------------------------------------------------------------------------------------------------------

whereis

If you don't know, where you can find a package you can use it, to get the exact path


root / >whereis apache22
apache22: /usr/ports/www/apache22

-----------------------------------------------------------------------------------------------------------------

df

The df command shows you some informations about your hard disk space (the parameter -h is useful here)


root / >df -h
Filesystem     Size    Used   Avail Capacity  Mounted on
/dev/da0s1a     17G    2.9G     13G    18%    /
devfs          1.0k    1.0k      0B   100%    /dev
/dev/da1s1d     77G    4.0k     71G     0%    /usr/home

-----------------------------------------------------------------------------------------------------------------

ps

ps shows you all running processes a user running at the moment!

You get the pid, the status, the time, a process is running, and the command or service which is executed!

[for Metin, if your came is named "game" and your server is running, you'll see there ./game for example)


root / >ps
  PID  TT  STAT      TIME COMMAND
  872  v0  Is+    0:00.00 /usr/libexec/getty Pc ttyv0
13771   0  Ss     0:00.04 -csh (csh)
13824   0  R+     0:00.00 ps

use the parameter -al, to get ALL processes listed

-----------------------------------------------------------------------------------------------------------------

kill

With kil you can kill a process by it's pid!

important parameters are -1 and -9!

-1: The kill stops the process and wait for the response, that it done everything well (saving files or s.th. else)

-9: The kill stops the process without asking anything! Just die is the slogan!


kill -9 <pid>

If you don't know the pid (but the name) or if you wanna kill a view processes with the same name (example Metin2 where you have the "game" for each Channel/Core) you can use killall!

Here same system with -1 and -9


killall -9 game

-----------------------------------------------------------------------------------------------------------------

ls

This command shows you every file in a directory.


ls -G

is painting files with special endings. Use the parameter -al to get ALL files listed ( .file are not listed with the single ls command)

-----------------------------------------------------------------------------------------------------------------

cat

It shows you the content of a file, without opening it in an editor!

In combination with the grep command, it's very easy to find a special sting in a file!


cat CONFIG
CHANNEL: 1
CHECK_MULTIHACK: 0
COMMON_SQL: localhost mt2 mt2!@# common
DB_ADDR: 127.0.0.1
DB_PORT: 13000
empire_whisper: 1
HOSTNAME: Game1
LOG_SQL: localhost mt2 mt2!@# log
MAP_ALLOW: 1 3 21 23 41 43 61 62 63 64 65
....(and so on)

-----------------------------------------------------------------------------------------------------------------

grep|egrep

It can be used additionaly to an other command or alone to "grep" s.th. out, what you are looking for!

For example (combination with "cat"):


cat CONFIG | grep "PORT"
DB_PORT: 15000
P2P_PORT: 161000
PORT: 13000

Or if you looking for a file with includes a special string:


grep -r "text string to search” directory-path

-----------------------------------------------------------------------------------------------------------------

cp/mv

With cp you can copy with mv move a file!


cp [source] [target]
mv [source] [target]

To copy/move a whole directory, you need to add the parameter -R


cp -R [source] [target]
mv -R [source] [target]

-----------------------------------------------------------------------------------------------------------------

rm

Use it to delete files


rm <file>

If you need to delete a whole direcotory add the parameter -rf (it is much more faster then deleting it by FileZilla or WinSCP)


rm -rf <file/directory>

-----------------------------------------------------------------------------------------------------------------

touch/mkdir

To create a new file without editing it, use touch. With mkdir you create a new directory.


touch <file-path>
mkdir <directory-path>

-----------------------------------------------------------------------------------------------------------------

tar

For packing or extracting with compression you can use this basic command.

I allways use it the the following parameters:

To pack:


tar czvf datei.tgz directory

To extract:


tar xzvf file.tgz

-----------------------------------------------------------------------------------------------------------------

pkg_info

This command shows you every package you have installed

-----------------------------------------------------------------------------------------------------------------

find

with find, you are able to search quickly for a file by its name and get the exact path.

For example "syserr"


find / -name "syserr"

You are also able to execute a command if it finds s.th.

For example, we delete the syserr while searching, if we find one


find . -name syserr -exec rm {} ;

To get all important CPU informations, you can use this:

Spoiler

sysctl -a | egrep -i 'hw.machine|hw.model|hw.ncpu'
hw.machine: amd64
hw.model: Intel(R) Xeon(R) CPU E5-2640 0 @ 2.50GHz
hw.ncpu: 3
hw.machine_arch: amd64

If you wanna know s.th. about your used memory(RAM/SWAP) and so on, you can install "free" (which is a basic command on linux)

It's an perl script, so you have to install perl if you doesn't

Spoiler

fetch http://www.cyberciti.biz/files/scripts/freebsd-memory.pl.txt
mv freebsd-memory.pl.txt /usr/local/bin/free
chmod +x /usr/local/bin/free

Command (possible output):


free
SYSTEM MEMORY INFORMATION:
mem_wire:         390885376 (    372MB) [ 18%] Wired: disabled for paging out
mem_active:  +    805543936 (    768MB) [ 38%] Active: recently referenced
mem_inactive:+    809562112 (    772MB) [ 39%] Inactive: recently not referenced
mem_cache:   +     31989760 (     30MB) [  1%] Cached: almost avail. for allocation
mem_free:    +     29843456 (     28MB) [  1%] Free: fully available for allocation
mem_gap_vm:  +       581632 (      0MB) [  0%] Memory gap: UNKNOWN
-------------- ------------ ----------- ------
mem_all:     =   2068406272 (   1972MB) [100%] Total real memory managed
mem_gap_sys: +     63307776 (     60MB)        Memory gap: Kernel?!
-------------- ------------ -----------
mem_phys:    =   2131714048 (   2032MB)        Total real memory available
mem_gap_hw:  +     15769600 (     15MB)        Memory gap: Segment Mappings?!
-------------- ------------ -----------
mem_hw:      =   2147483648 (   2048MB)        Total real memory installed

SYSTEM MEMORY SUMMARY:
mem_used:        1276088320 (   1216MB) [ 59%] Logically used memory
mem_avail:   +    871395328 (    831MB) [ 40%] Logically available memory
-------------- ------------ ----------- ------
mem_total:   =   2147483648 (   2048MB) [100%] Logically total memory

One more thing is the traffic!

Spoiler

To get a screen like this:

291440darkstat.png.78ad8a24fd9a8b2492485

1. Install:


cd /usr/ports/net-mgmt/darkstat && make install clean

2. Enable in /etc/rc.conf our example network interface is em0


darkstat_enable="YES"
darkstat_interface="em0"

3. start the service


service darkstat start

4. start a session (port is not for listening It's for the web-application)


darkstat -p <port> -b <server_ip> -i <network_interface>

you will see your stats on: <server_ip>:<port>

For example:


darkstat -p 10010 -b 10.5.0.2 -i em0

now go on http://10.5.0.2:10010

Kind regards

  • Confused 1
  • Good 1
  • Love 9
Link to comment
Share on other sites

I thought, this are the basics you should know if you work with the command line...!

You can use almost everything on linux systems, too (some even on windows)

 

If someone have a command, or an other question, how he/she can do anything with command line, I'll in the future add commands and/or ways how to do or deal with it

#Edit: Thanks, my mistake, edited it ;)

Link to comment
Share on other sites

I thought, this are the basics you should know if you work with the command line...!

You can use almost everything on linux systems, too (some even on windows)

 

If someone have a command, or an other question, how he/she can do anything with command line, I'll in the future add commands and/or ways how to do or deal with it

#Edit: Thanks, my mistake, edited it ;)

no, my point was I tried it on a regular user but it didn't work. It works on root.

Link to comment
Share on other sites

Try this:

env | grep -i shell

the output should be:

SHELL=/bin/csh

But the default output (for normal useres) is:

SHELL=/bin/sh

Execute this in command line:

chsh -s /bin/csh

And the prompt will change after su or relogg on the user ;)
Like this:

shell_change.png

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.