Page not found – ShopingServer Wiki https://wiki.shopingserver.com Tutorials and Articles About Technology and Gadgets Fri, 18 Sep 2020 18:54:09 +0000 en-US hourly 1 https://wordpress.org/?v=5.5.14 https://wiki.shopingserver.com/wp-content/uploads/2018/07/cropped-favicon-150x150.png Page not found – ShopingServer Wiki https://wiki.shopingserver.com 32 32 Learn phrases, commands, and blocks in Java (plain language) https://wiki.shopingserver.com/learn-phrases-commands-and-blocks-in-java-plain-language/ https://wiki.shopingserver.com/learn-phrases-commands-and-blocks-in-java-plain-language/#respond Fri, 18 Sep 2020 18:54:09 +0000 http://wiki.shopingserver.com/?p=27862 In this tutorial, you will learn about expressions, statements, blocks, and the difference between a phrase and a commands

We used phrases, commands, and blocks in previous tutorials without going into too much detail about them. 

Now you know what variables, operators and literals are, so it will be easier to understand these concepts.

Java Expressions

Expressions include variables, operators, literals, and method calls that evaluate a single value.

Let’s give an example:

int score;

score = 90;

Here, score = 90 is the expression that returns int.

Double a = 2.2, b = 3.4, result;

result = a + b – 3.4;

Here, a + b is 3.4.

if (number1 == number2)

System.out.println (“Number 1 is larger than number 2”);

Here, number2 == number1 is the expression that boolean returns. Similarly, “Number 1 is larger than number 2” is a string expression.

Java Statements

Commands form a complete execution unit. For example,

int score = 9 * 5;

Here, 9 * 5 is a statement that returns 45, and int score = 9 * 5 is a command.

Phrases are part of commands.

Grammatical expressions

Some expressions can be used with; Terminated are known as commands. For example:

number = 10;

Here, number = 10 is a phrase and number = 10; Is a command that the compiler can execute.

++ number;

Here, ++ number is the expression while ++ number; Is a command.

Definitive commands

Defines commands that define variables. For example,

Double tax = 9.5;

The above command defines the tax variable with an initial value of 9.5.

There are also control flow commands used in decision making and loops in Java. You will learn control flow commands in later tutorials.

3- Java block

A block is a group of expressions (zero or more) enclosed in brackets}}. For example,

  1. class AssignmentOperator {
  2. public static void main (String [] args) {
  3. String band = “Beatles”;
  4. if (band == “Beatles”) {// start of block
  5. System.out.print (“Hey”);
  6. System.out.print (“Jude!”);
  7. } // end of block
  8. }
  9. }

Above are two phrases

System.out.print (“Hey”);

And

System.out.print (“Jude!”);

Inside the listed block.

A block may have no expression. Consider the following examples:

class AssignmentOperator {

public static void main (String [] args) {

if (10> 5) {// start of block

} // end of block

}

}

class AssignmentOperator {

public static void main (String [] args) {// start of block

} // end of block

}

]]>
https://wiki.shopingserver.com/learn-phrases-commands-and-blocks-in-java-plain-language/feed/ 0
Linux: Find Out Directory Size Command https://wiki.shopingserver.com/linux-find-directory-size-command/ https://wiki.shopingserver.com/linux-find-directory-size-command/#respond Sat, 06 Jan 2018 10:13:47 +0000 http://wiki.shopingserver.com/?p=18589 I am a new Linux user. How do I find out size of a directory on Linux operating systems using command line options?

 

You need to use the du command:

[a] Find and estimate file space usage.

[b] Summarize disk usage of each FILE/Directory/Folder.

[c] Shows the sizes of directories and files.

Syntax

The basic syntax is:

du

du dirName

du [options] dirName

Examples

Without any options, du command shows the names and used space for each directories including all sub-directories in the current directory:

du

 

Sample outputs:

Fig.01: du command in action

To find information about /etc and /home/nixcraft directory, enter:

du /path/to/dir

du /etc

du /home/nixcraft

du /root /home/nixcraft

Pass the -h option to get output in human readable format i.e. show output in kilobytes (K), megabytes (M) and gigabytes (G):

du -h /etc

du -h /dir1/file2

du -h /root

du -h

 

Sample outputs:

8.0K ./.vim

24K ./scripts

48K ./.ssh

16K ./.keychain

2.2M ./.lftp

2.4M .

Pass the -s option to see the total disk space used by a directory:

du -sh

du -sh /etc/

du -sh /etc /home/ /securebackup/

 

Sample outputs:

4.1M /etc

152K /home/

902M /securebackup/

Pass the -c to see a grand total for all of the files, type:

du -csh /root/ /etc/ /home/

 

Sample outputs:

2.4M /root/

4.1M /etc/

152K /home/

6.6M total

See also

UNIX disk usage command examples – include command line tool such as du, df, ncdu, and GUI tools.

See du(1) and examples.

 

 

]]>
https://wiki.shopingserver.com/linux-find-directory-size-command/feed/ 0
Debian / Ubuntu: apt-get Force Reinstall Package https://wiki.shopingserver.com/debian-ubuntu-apt-get-force-reinstall-package/ https://wiki.shopingserver.com/debian-ubuntu-apt-get-force-reinstall-package/#respond Sat, 06 Jan 2018 10:02:32 +0000 http://wiki.shopingserver.com/?p=18573 I am a new Debian Linux v.7.x / Ubuntu Linux LTS user. How do I reinstall a package using apt-get command line?

 

The Advanced Packaging Tool (APT) works on both Debian / Ubuntu and it can handle the installation and removal of software. You need use apt-get command as follows to forcefully reinstall package. The syntax is:

apt-get –reinstall install PackageNameHere

OR

apt-get –reinstall install Package1 Package2

The –reinstall option re-install packages that are already installed and at the newest version.

Pro tip: Backup configuration files before you reinstall packages. For example, if you are reinstalling nginx web server package, backup /etc/nginx/ with cp command i.e. mkdir /root/nginx.mmddyyyy/; cp -avr /etc/nginx/* /root/nginx.mmddyyy/

Examples

The following command will reinstall rsync package. Open a terminal and then type:

$ sudo apt-get –reinstall install rsync

 

OR

# apt-get –reinstall install rsync

 

Sample outputs:

Fig.01: Debian / Ubuntu Linux reinstall a package using apt-get command

If above method failed for you, try the following syntax. Make sure you backup config file before typing the following commands. Please note that the –purge option is identical to remove except that packages are removed and purged including any configuration files are deleted too.

sudo apt-get –purge remove package1

sudo apt-get install package1

See also

See man pages for more info – apt-get(8),dpkg(1),cp(1)

 

 

]]>
https://wiki.shopingserver.com/debian-ubuntu-apt-get-force-reinstall-package/feed/ 0
HowTo: OS X Take a Screenshot On My Mac Desktop https://wiki.shopingserver.com/howto-os-x-take-screenshot-mac-desktop/ https://wiki.shopingserver.com/howto-os-x-take-screenshot-mac-desktop/#respond Sat, 06 Jan 2018 09:54:52 +0000 http://wiki.shopingserver.com/?p=18563 I can use Shutter app in GNU/Linux to take a screenshot of a specific area, window, whole screen, or even of a website. How do I take a screenshot on my mac book pro/mini desktop using Mac OS X?

 

Shutter application not available on Apple OS X or Apple based systems. However, you can take pictures of the screen (screenshots). They are saved as files on the desktop or put a screenshot in the Clipboard using Mac OS X keyboard shortcuts. No need to download and install paid applications. You can use the following keyboard shortcuts to capture:

The whole screen / desktop.

Part of the screen / desktop.

Part of the menu or toolbar.

Please note that you can also take screenshots using the Grab app.

How do I take a picture of the whole screen?

You need to hold down Command (⌘), and press Shift & 3 keys simultaneously:

Command (⌘)-Shift-3

Pictures of the screenshot is saved as files on the desktop in the following format i.e. file name will be as follows:

Screen Shot 2013-08-09 at 2.57.32 PM

How do I take a picture of part of the screen?

You need to hold down Command (⌘), and press Shift & 4 keys simultaneously:

Command (⌘)-Shift-4

Make sure you drag the cross-hair (X) pointer to select the area. Continue to press the mouse button, release the keys, and then press Shift, Option, or the Space bar while you drag to resize the selection area. When you are ready to take a picture, release the mouse button.

Note: To cancel, press Escape before you release the mouse button.

The default screenshot format is set to .png file.

Say hello to screencapture command

You can use screencapture command from the Terminal to capture images from the screen and save them to a file or the clipboard. The syntax is:

screencapture /path/to/file.jpg

screencapture [option] /path/to/file.jpg

The following command will capture the entire desktop and save it to ~/Desktop/my-shot-1.png file:

screencapture ~/Desktop/my-shot-1.png

 

To view your screenshotp go to desktop or type the following command from the terminal:

open ~/Desktop/my-shot-1.png

 

Pass the -c option to force screen capture to go to the clipboard:

screencapture -c

 

Press command (⌘)-v to paste screenshot in your office or photo editing application.

Pass the -i option to capture screen interactively, by selection or window. The control key will cause the screen shot to go to the clipboard. The space key will toggle between mouse selection and window selection modes. The escape key will cancel the interactive screen shot:

screencapture -i ~/Desktop/my-shot-1.png

 

The following is a list of all supported options:

-c      Force screen capture to go to the clipboard.

 

-C      Capture the cursor as well as the screen.  Only allowed in non-interactive modes.

 

-i      Capture screen interactively, by selection or window.  The control key will cause the screen shot to go to the clipboard.  The space key will

toggle between mouse selection and window selection modes.  The escape key will cancel the interactive screen shot.

 

-m      Only capture the main monitor, undefined if -i is set.

 

-M      Open the taken picture in a new Mail message.

 

-o      In window capture mode, do not capture the shadow of the window.

 

-P      Open the taken picture in a Preview window.

 

-s      Only allow mouse selection mode.

 

-S      In window capture mode, capture the screen instead of the window.

 

-t       Image format to create, default is png (other options include pdf, jpg, tiff and other formats).

 

-T       Take the picture after a delay of , default is 5.

 

-w      Only allow window selection mode.

 

-W      Start interaction in window selection mode.

 

-x      Do not play sounds.

 

-a      Do not capture attached windows.

 

-r      Do not add screen dpi meta data to captured file.

References

KB – PH11229.

screencapture(1) for more information.

 

 

]]>
https://wiki.shopingserver.com/howto-os-x-take-screenshot-mac-desktop/feed/ 0
Linux: Find Out What Is Using TCP Port 80 https://wiki.shopingserver.com/linux-find-using-tcp-port-80/ https://wiki.shopingserver.com/linux-find-using-tcp-port-80/#respond Sat, 06 Jan 2018 09:53:19 +0000 http://wiki.shopingserver.com/?p=18561 H

ow do I find out what is listing or using tcp port number 80 on Linux based systems using command line options?

 

You can use any one of the following command to find out what is using tcp or udp port number 80 on Linux operating systems:

netstat – a command-line tool that displays network connections, routing tables, and a number of network interface statistics.

fuser – a command line tool to identify processes using files or sockets.

lsof – a command line tool to list open files under Linux / UNIX to report a list of all open files and the processes that opened them.

/proc/$pid/ file system – Under Linux /proc includes a directory for each running process (including kernel processes) at /proc/PID, containing information about that process, notably including the processes name that opened port.

Examples

Open a terminal and then type the following command as root user:

netstat command find out what is using port 80

Type the following command

# netstat -tulpn | grep :80

 

OR pass the –color option to grep command as follows:

# netstat -tulpn | grep –color :80

 

Sample outputs:

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      1215/nginx

Where,

0 0.0.0.0:80 – Source IP:Port

1215/nginx – PID/Process name

The tcp port 80 is opened and used by nginx web server. Type the following command to find out more about nginx:

whatis nginx

whereis nginx

Note: You may need to install lsof and fuser command.

Use /proc/$pid/exec file find out what is using port 80

First, find out the processes PID that opened tcp port 90, enter:

# fuser 80/tcp

 

Sample outputs:

80/tcp:              12161 21776 25250 25393

Finally, find out process name associated with PID # 3813, enter:

# ls -l /proc/12161/exe

 

Sample outputs:

lrwxrwxrwx. 1 root root 0 Aug  9 13:28 /proc/12161/exe -> /usr/sbin/lighttpd

Find out more about lighttpd:

man lighttpd

whatis lighttpd

whereis lighttpd

Sample outputs:

lighttpd             (8)  – a fast, secure and flexible web server

lighttpd: /usr/sbin/lighttpd /usr/lib64/lighttpd /usr/share/man/man8/lighttpd.8.gz

You can use package manager to dig into lighttpd:

# rpm -qa | grep lighttpd

 

Sample outputs:

lighttpd-1.4.32-1.el6.x86_64

To find out more about lighttpd-1.4.32-1.el6.x86_64 package, type:

# yum info lighttpd-1.4.32-1.el6.x86_64

 

Sample outputs:

Loaded plugins: auto-update-debuginfo, protectbase, rhnplugin, security

This system is receiving updates from RHN Classic or RHN Satellite.

0 packages excluded due to repository protections

Installed Packages

Name        : lighttpd

Arch        : x86_64

Version     : 1.4.32

Release     : 1.el6

Size        : 664 k

Repo        : installed

Summary     : A web server more optimized for speed-critical environments.

URL         : http://lighttpd.net/

License     : Revised BSD

Description : It is a secure and fast web server a very low memory footprint compared

: to other webservers and takes care of cpu-load.

OR use rpm command:

# rpm -qi lighttpd

 

Sample outputs:

Name        : lighttpd                     Relocations: (not relocatable)

Version     : 1.4.32                            Vendor: nixCraft

Release     : 1.el6                         Build Date: Sun 03 Feb 2013 03:22:08 AM CST

Install Date: Mon 04 Feb 2013 04:44:26 AM CST      Build Host: rhel6.nixcraft.net.in

Group       : System Environment/Daemons    Source RPM: lighttpd-1.4.32-1.el6.src.rpm

Size        : 680402                           License: Revised BSD

Signature   : (none)

URL         : http://lighttpd.net/

Summary     : A web server more optimized for speed-critical environments.

Description :

It is a secure and fast web server a very low memory footprint compared

to other webservers and takes care of cpu-load.

Debian / Ubuntu Linux user can use the following commands:

# dpkg –list | grep lighttpd

# apt-cache search lighttpd

# apt-cache show lighttpd

 

Sample outputs from the last command:

Package: lighttpd

Priority: optional

Section: universe/web

Installed-Size: 841

Maintainer: Ubuntu Developers

Original-Maintainer: Debian lighttpd maintainers

Architecture: amd64

Version: 1.4.28-2ubuntu4

Provides: httpd, httpd-cgi

Depends: libattr1 (>= 1:2.4.46-5), libbz2-1.0, libc6 (>= 2.4), libgamin0 | libfam0, libldap-2.4-2 (>= 2.4.7), libpcre3 (>= 8.10), libssl1.0.0 (>= 1.0.0), zlib1g (>= 1:1.1.4), lsb-base (>= 3.2-14), mime-support, libterm-readline-perl-perl

Recommends: spawn-fcgi

Suggests: openssl, rrdtool, apache2-utils, ufw

Conflicts: cherokee (<= 0.6.1-1)

Filename: pool/universe/l/lighttpd/lighttpd_1.4.28-2ubuntu4_amd64.deb

Size: 279838

MD5sum: 65aedfd0e0ab6d3ee28e7b394567ed22

SHA1: 34a9156fa3d23635eb24efb436de585c0594f046

SHA256: 751d6f8309d249740d7aab240a74b6bae713e524cf6815544b6cdbb6107fded2

Description-en: A fast webserver with minimal memory footprint

lighttpd is a small webserver and fast webserver developed with

security in mind and a lot of features.

It has support for

* CGI, FastCGI and SSI

* virtual hosts

* URL rewriting

* authentication (plain files, htpasswd, ldap)

* transparent content compression

* conditional configuration

and configuration is straight-forward and easy.

Homepage: http://www.lighttpd.net

Description-md5: 267ee2989b526d8253e822e7d8244ccd

Bugs: https://bugs.launchpad.net/ubuntu/+filebug

Origin: Ubuntu

lsof command find out what is using port 80

Type the following command

# lsof -i :80 | grep LISTEN

 

Sample outputs:

apache2   1607     root    3u  IPv4   6472      0t0  TCP *:www (LISTEN)

apache2   1616 www-data    3u  IPv4   6472      0t0  TCP *:www (LISTEN)

apache2   1617 www-data    3u  IPv4   6472      0t0  TCP *:www (LISTEN)

See also

Linux: Find Out Which Process Is Listening Upon a Port

ss: Display Linux TCP / UDP Network and Socket Information

See man pages for more info lsof(8),fuser(1),proc(5),netstat(8),ss(8)

 

 

]]>
https://wiki.shopingserver.com/linux-find-using-tcp-port-80/feed/ 0
Fedora Linux: Restart / Stop / Start DHCPD Server Command https://wiki.shopingserver.com/fedora-linux-restart-stop-start-dhcpd-server-command/ https://wiki.shopingserver.com/fedora-linux-restart-stop-start-dhcpd-server-command/#respond Sat, 06 Jan 2018 09:51:27 +0000 http://wiki.shopingserver.com/?p=18559 I

am a new Fedora Linux version 18 system administrator. How do I restart dhcpd server using command line options in Fedora Linux server running on HP server hardware?

 

DHCP (Dynamic Host Configuration Protocol) is a protocol which allows individual devices on an IP network to get their own network configuration information such as follows from a DHCP server:

IP address

Subnetmask

Broadcast address

DNS server IP address

Default gateway IP address and more

The dhcp package includes the ISC DHCP service, server and relay agent.

Fedora start / stop / restart DHCPD (latest version)

Alert: You need Fedora Linux version 15 or above to use the following commands.

To restart dhcpd service, open a terminal or login using ssh and then type:

# systemctl restart dhcpd.service

 

To stop dhcpd service, type:

# systemctl stop dhcpd.service

 

To start dhcpd service, type:

# systemctl start dhcpd.service

Note: By default, the DHCPD service does not start at boot time. To configure the daemon to start automatically at boot time, type:

# systemctl enable dhcpd.service

Fedora start / stop / restart DHCPD (older version)

Alert: You need Fedora Linux version 14 or older to use the following commands. Also, commands are compatible with RHEL/CentOS Linux too.

To restart dhcpd service, open a terminal or login using ssh and then type:

# service dhcpd restart

 

To stop dhcpd service, type:

# service dhcpd stop

 

To start dhcpd service, type:

# service dhcpd start

Note: By default, the DHCPD service does not start at boot time. To configure the daemon to start automatically at boot time, type:

# chkconfig dhcpd on

 

 

]]>
https://wiki.shopingserver.com/fedora-linux-restart-stop-start-dhcpd-server-command/feed/ 0
HowTo: Pronounce Mac OS X https://wiki.shopingserver.com/howto-pronounce-mac-os-x/ https://wiki.shopingserver.com/howto-pronounce-mac-os-x/#respond Sat, 06 Jan 2018 09:50:10 +0000 http://wiki.shopingserver.com/?p=18557 I

am a new Apple Mac book pro user. Is Mac OS X pronounced as “Mac OS E-X” or “Mac OS Ten”? How do you pronounce the Apple Mac os X? How do I find out OS X version using command line tool?

 

Short answer – The Apple Mac OS X is pronounced as “Mac OS Ten”.

How do I find out the current OS X version?

Visit Apple menu > select “About This Mac” to see the current version:

Fig.01 OS X version

From the Fig.01 the current version of Mac OS is “Mac OS Ten” dot eight. Where,

Mac OS name – Mac OS Ten

Major version – 10.8

Update to major version – .4

Pronounced as –  Mac OS Ten dot eight dot four  or  Mac OS Ten point eight point four

Here is output from macOS Sierra:

Fig.02: macOS Sierra

Finding Mac OS X version from command line

To display Mac OS X operating system version information use sw_vars command. Open the Terminal and type the following command:

$ sw_vers

 

Sample outputs:

Fig.03: Finding Mac OS X version using sw_vers command line tool

 

Here is the output from the lastest version of macOS Sierra:

$ sw_vers

ProductName: Mac OS X

ProductVersion: 10.12

BuildVersion: 16A323

Say hello to ‘say’ command line tool

say is command line tool. It uses the Speech Synthesis manager to convert input text to audible speech and either play it through the sound output device chosen in System Preferences or save it to an AIFF file. Open the Terminal and type the following command:

say  Mac OS X

say  Mac OS X .8.4

The following command uses sw_vers as bash command line substitute to find out the current version and pronounce it using the say command:

say $(sw_vers -productName && sw_vers -productVersion | sed  s/10// )

 

 

]]>
https://wiki.shopingserver.com/howto-pronounce-mac-os-x/feed/ 0
Linux / Unix: Sort ls Command Output By Last Modified Date and Time https://wiki.shopingserver.com/linux-unix-sort-ls-command-output-last-modified-date-time/ https://wiki.shopingserver.com/linux-unix-sort-ls-command-output-last-modified-date-time/#respond Sat, 06 Jan 2018 09:48:54 +0000 http://wiki.shopingserver.com/?p=18555 I

download lots of files in ~/Downloads/ folder in Ubuntu Linux and OS X desktop. How do I show last downloaded file first using the ls command? How do I sort the output of ls command by last modified date?

 

You need to pass the -t option to the ls command. The -t option sort by time modified i.e. most recently modified first before sorting the operands by lexicographical order. In other words, last downloaded file can be displayed using the following command. Open the Terminal application and type the following command.

Syntax

The syntax is:

ls -t

ls -lt | less

ls -lt ~/Downloads/ | less

 

Sample outputs:

total 60754328

drwxr-xr-x  3 vivek  staff         102 Aug 25 13:18 ImageOptim.app

-rw-r–r–@ 1 vivek  staff   301746331 Aug 25 01:25 data-db2-sample.rar

-rw-r–r–@ 1 vivek  staff     1727030 Aug 25 01:14 testdisk-6.14.mac_intel.tar.tar.bz2

-rw-r–r–@ 1 vivek  staff       23850 Aug 24 22:36 english-68.zip

-rw-r–r–@ 1 vivek  staff       72488 Aug 24 22:05 36363537dkgpd.pdf

drwxr-xr-x@ 3 vivek  staff         170 Aug 24 19:58 backups

drwxr-xr-x@ 4 vivek  staff         306 Aug 24 19:56 tarballs

-rw——-@ 1 vivek  staff       39748 Aug 24 13:22 Account-xyz.pdf

-rw——-@ 1 vivek  staff       35583 Aug 24 13:21 Portfolio-Update-FY13-14.pdf

-rw——-@ 1 vivek  staff      141695 Aug 24 01:26 13290.pdf

drwxr-xr-x@ 2 vivek  staff         136 Aug 24 00:32 hd-video-raw-files

-rw-r–r–@ 1 vivek  staff  1359349025 Aug 23 21:04 youtube-sample.mp4

drwxr-xr-x@ 2 vivek  staff         170 Aug 23 21:03 delme

-rw-r–r–@ 1 vivek  staff      120587 Aug 23 19:00 Screenshot-System-Monitor.png

-rw-r–r–@ 1 vivek  staff       23301 Aug 22 13:21 sad-tux.png

….

..

….

Pass the -r option to reverse the order of the sort to get reverse lexicographical order or the oldest entries first (or largest files last, if combined with sort by size), enter:

ls -tr

ls -ltr | less

ls -ltr ~/Downloads/ | less

 

Sample outputs:

total 60754328

-rwxr-xr-x@ 1 vivek  staff      115262 Jan  1  1970 P4.pdf

-rw-r–r–  1 vivek  staff      135734 Sep 16  2011 game.idx

-rw-r–r–  1 vivek  staff       51111 Sep 16  2011 game.English.srt

-rwxr-xr-x@ 1 vivek  staff      331201 Sep  6  2012 Portfolio_Recommendations_Comprehensive_Sep12.pdf

-rw-r–r–  1 vivek  staff   301746245 Sep 25  2012 hp-ux-to-rhel6-guide.pdf

-rwxr-xr-x@ 1 vivek  staff       13350 Mar 13 16:44 DC-location-Towns.xlsx

-rw-r–r–@ 1 vivek  staff   574423040 Jun 10 16:33 data-center-opening.avi

-rw-r–r–@ 1 vivek  staff     2375468 Jun 15 05:04 backups.rar

-rw-r–r–  1 vivek  staff     2631709 Jun 15 05:07 last-good-know-backups.pdf

….

..

Sort by modification time, newest first and other options

Make sure you pass the -A (list all entries except for . and ..) or -a (include directory entries whose names begin with a dot) option to see hidden files:

ls -Altr ~/Downloads/ | less

ls -alt ~/Downloads/ | less

The following option turned on human readable output:

$ ls -halt

$ ls -halt | more

 

Sample outputs:

Fig.01: Print human readable sizes when used with the -l/-s option

Recommended readings

See ls(1) for more information.

 

 

]]>
https://wiki.shopingserver.com/linux-unix-sort-ls-command-output-last-modified-date-time/feed/ 0
How To Find a Directory On Linux Based System https://wiki.shopingserver.com/find-directory-linux-based-system/ https://wiki.shopingserver.com/find-directory-linux-based-system/#respond Sat, 06 Jan 2018 09:47:25 +0000 http://wiki.shopingserver.com/?p=18553 I

just switched from MS-Windows server admin to Debian Linux server admin role. I need to find a directory called project.images. I was also told that the locate command is the simplest and quickest way to find the locations of files and directories on Linux. But, the locate command is not working out for me. How do I find project.images directory using command line options only?

 

You need to use the find command. It is used to locate files on a Linux or Unix like system. The locate command will searches through a prebuilt database of files generated by updatedb.

 

The find command will search live file-system for files that match the search criteria.

Syntax

The find command syntax is:

find /where/to/look/up criteria action

 

OR

find /dir/path/look/up criteria action

 

OR

find /dir/path/look/up -name  dir-name-here

 

OR

find /dir/path/look/up -name  pattern

 

OR

find /dir/path/look/up -name  dir-name-here  -print

 

OR

find /dir/path/look/up -name  dir-name-here

 

OR

find / -name  dir-name-here

 

OR

find / -type d -name  dir-name-here

 

OR

find / -type d -name  dir-name-here  2>/dev/null

Examples

The following example will show all files in the current directory and all subdirectories:

find

find .

find . -print

Finding a directory

To find a directory called apt in / (root) file system, enter:

Alert: When searching / (root) file system, you need to run the find command as root user.

find / -type d -name  apt

Sample outputs:

/var/log/apt

/var/lib/apt

/var/cache/apt

/etc/apt

/etc/logrotate.d/apt

/etc/cron.daily/apt

How to find a directory named Documents on Linux?

Type the following command to search for Documents directory in your $HOME dir:

$ find $HOME -type d -name Documents

 

Sample outputs:

/home/vivek/Documents

Getting a detailed list of files/dirs

Pass the -ls to list current file in ls command output format:

find  / -name  apt  -ls

Sample outputs:

4719035    4 drwxr-xr-x   2 root     root         4096 Aug 22 06:25 /var/log/apt

4718597    4 drwxr-xr-x   5 root     root         4096 Aug  4 13:46 /var/lib/apt

4718601    4 drwxr-xr-x   3 root     root         4096 Aug  8 09:37 /var/cache/apt

917524    4 drwxr-xr-x   6 root     root         4096 Jun 18 02:28 /etc/apt

917721    4 -rw-r–r–   1 root     root          173 Apr 15  2011 /etc/logrotate.d/apt

918762   16 -rwxr-xr-x   1 root     root        14985 Mar 14 12:48 /etc/cron.daily/apt

How do I list only directories?

Just find directories and skip file names pass the -type d option as follows:

find  / -type d -name  apt  -ls

Sample outputs:

4719035    4 drwxr-xr-x   2 root     root         4096 Aug 22 06:25 /var/log/apt

4718597    4 drwxr-xr-x   5 root     root         4096 Aug  4 13:46 /var/lib/apt

4718601    4 drwxr-xr-x   3 root     root         4096 Aug  8 09:37 /var/cache/apt

917524    4 drwxr-xr-x   6 root     root         4096 Jun 18 02:28 /etc/apt

How do I perform a case insensitive search?

Replace -name option with -iname as follows:

find  / -type d -iname  apt  -ls

OR

find  / -type d -iname  apt

The patterns ‘apt’ match the directory names ‘apt’, ‘APT’, ‘Apt’, ‘apT’, etc.

How do I find a directory called project.images?

Type any one of the following command:

find  / -type d -iname  project.images  -ls

OR

find  / -type d -name  project.images  -ls

OR

find  / -type d -name  project.images

It is also possible to use the wild cards as follows:

find  / -type d -name  project.*

find  /dir/to/search/ -type d -name  project.image??

A note about locate command

To search for a file/dir named exactly project.images (not *project.images*), type:

locate -b  \project.images

See also

All find command examples from our /faq/ sections.

find(1)

 

 

]]>
https://wiki.shopingserver.com/find-directory-linux-based-system/feed/ 0
Mac OS X: Set / Change $PATH Variable https://wiki.shopingserver.com/mac-os-x-set-change-path-variable/ https://wiki.shopingserver.com/mac-os-x-set-change-path-variable/#respond Sat, 06 Jan 2018 09:45:50 +0000 http://wiki.shopingserver.com/?p=18551 I

need to add dev tools (such as JDK and friends) to my PATH. How do I change $PATH variable in OS X 10.8.x? Where does $PATH get set in OS X 10.8 Mountain Lion?

 

$PATH is nothing but an environment variable on Linux, OS X, Unix-like operating systems, and Microsoft Windows. You can specify a set of directories where executable programs are located using $PATH. The $PATH variable is specified as a list of directory names separated by colon (:) characters. To print the current settings, open the Terminal and then type:

echo  $PATH

OR

printf  %s\n  $PATH

Sample outputs:

Fig.01: Displaying the current $PATH settings using echo / printf on OS X

OS X: Change your PATH environment variable

You can add path to any one of the following method:

$HOME/.bash_profile file using export syntax.

/etc/paths.d directory.

Method #1: $HOME/.bash_profile file

The syntax is as follows:

export PATH=$PATH:/new/dir/location1

export PATH=$PATH:/new/dir1:/dir2:/dir/path/no3

In this example, add /usr/local/sbin/modemZapp/ directory to $PATH variable. Edit the file $HOME/.bash_profile, enter:

vi $HOME/.bash_profile

 

OR

vi ~/.bash_profile

 

Append the following export command:

export PATH=$PATH:/usr/local/sbin/modemZapp

Save and close the file. To apply changes immedialty enter:

source $HOME/.bash_profile

 

OR

. $HOME/.bash_profile

 

Finally, verify your new path settings, enter:

echo $PATH

 

Sample outputs:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/sbin/modemZapp

Method #2: /etc/paths.d directory

Apple recommends the path_helper tool to generate the PATH variable i.e. helper for constructing PATH environment variable. From the man page:

The path_helper utility reads the contents of the files in the directories /etc/paths.d and /etc/manpaths.d and appends their contents to the PATH and MANPATH environment variables respectively.

(The MANPATH environment variable will not be modified unless it is already set in the environment.)

Files in these directories should contain one path element per line.

Prior to reading these directories, default PATH and MANPATH values are obtained from the files /etc/paths and /etc/manpaths respectively.

To list existing path, enter:

ls -l /etc/paths.d/

 

Sample outputs:

total 16

-rw-r–r–  1 root  wheel  13 Sep 28  2012 40-XQuartz

You can use the cat command to see path settings in 40-XQuartz:

cat /etc/paths.d/40-XQuartz

 

Sample outputs:

/opt/X11/bin

To set /usr/local/sbin/modemZapp to $PATH, enter:

sudo -s  echo  /usr/local/sbin/modemZapp  > /etc/paths.d/zmodemapp

OR use vi text editor as follows to create /etc/paths.d/zmodemapp file:

sudo vi /etc/paths.d/zmodemapp

 

and append the following text:

/usr/local/sbin/modemZapp

Save and close the file. You need to reboot the system. Alternatively, you can close and reopen the Terminal app to see new $PATH changes.

Conclusion

Use $HOME/.bash_profile file when you need to generate the PATH variable for a single user account.

Use /etc/paths.d/ directory via the path_helper tool to generate the PATH variable for all user accounts on the system. This method only works on OS X Leopard and higher.

See also:

Customize the bash shell environments from the Linux shell scripting wiki.

UNIX: Set Environment Variable

Man pages – bash(1), path_helper(8)

 

 

]]>
https://wiki.shopingserver.com/mac-os-x-set-change-path-variable/feed/ 0